34 #include <unordered_map>
36 #include "cpprest/details/basic_types.h"
37 #include "cpprest/asyncrt_utils.h"
59 extern bool g_keep_json_object_unsorted;
72 #define ENABLE_JSON_VALUE_VISUALIZER
154 _ASYNCRTIMP
explicit value(utility::string_t
value);
165 _ASYNCRTIMP
explicit value(utility::string_t
value,
bool has_escape_chars);
182 _ASYNCRTIMP
explicit value(
const utility::char_t*
value);
199 _ASYNCRTIMP
explicit value(
const utility::char_t*
value,
bool has_escape_chars);
209 _ASYNCRTIMP
value(
value &&) CPPREST_NOEXCEPT ;
221 _ASYNCRTIMP value &operator=(value &&) CPPREST_NOEXCEPT ;
229 static _ASYNCRTIMP value __cdecl
null();
236 static _ASYNCRTIMP value __cdecl
number(
double value);
243 static _ASYNCRTIMP value __cdecl
number(int32_t value);
250 static _ASYNCRTIMP value __cdecl
number(uint32_t value);
257 static _ASYNCRTIMP value __cdecl
number(int64_t value);
264 static _ASYNCRTIMP value __cdecl
number(uint64_t value);
271 static _ASYNCRTIMP value __cdecl
boolean(
bool value);
282 static _ASYNCRTIMP value __cdecl
string(
utility::string_t value);
294 static _ASYNCRTIMP value __cdecl
string(
utility::string_t value,
bool has_escape_chars);
299 static _ASYNCRTIMP value __cdecl
string(
const std::string &value);
316 static _ASYNCRTIMP
json::value __cdecl
object(std::vector<std::pair<::utility::string_t, value>> fields,
bool keep_order =
false);
410 _ASYNCRTIMP
static value __cdecl
parse(
const utility::string_t &value);
418 _ASYNCRTIMP
static value __cdecl
parse(
const utility::string_t &value, std::error_code &errorCode);
424 _ASYNCRTIMP utility::string_t
serialize()
const;
430 CASABLANCA_DEPRECATED(
"This API is deprecated and has been renamed to avoid confusion with as_string(), use ::web::json::value::serialize() instead.")
431 _ASYNCRTIMP
utility::string_t to_string() const;
438 _ASYNCRTIMP static value __cdecl
parse(
utility::istream_t &input);
446 _ASYNCRTIMP static value __cdecl
parse(
utility::istream_t &input, std::error_code &errorCode);
455 _ASYNCRTIMP
static value __cdecl
parse(std::istream& stream);
467 _ASYNCRTIMP
static value __cdecl
parse(std::istream& stream, std::error_code& error);
473 _ASYNCRTIMP
void serialize(std::ostream& stream)
const;
501 _ASYNCRTIMP
bool as_bool()
const;
533 _ASYNCRTIMP
const utility::string_t&
as_string()
const;
540 _ASYNCRTIMP
bool operator==(
const value& other)
const;
549 return !((*this) == other);
557 bool has_field(
const utility::string_t &key)
const;
564 CASABLANCA_DEPRECATED(
"This API is deprecated and will be removed in a future release, use json::value::at() instead.")
565 value
get(const
utility::string_t &key) const;
571 _ASYNCRTIMP
void erase(
size_t index);
584 _ASYNCRTIMP json::value&
at(
size_t index);
591 _ASYNCRTIMP const json::value&
at(
size_t index) const;
598 _ASYNCRTIMP json::value&
at(const
utility::string_t& key);
605 _ASYNCRTIMP const json::value&
at(const
utility::string_t& key) const;
612 _ASYNCRTIMP value & operator [] (const
utility::string_t &key);
617 _ASYNCRTIMP value &
operator [] (
const std::string &key)
630 CASABLANCA_DEPRECATED(
"This API is deprecated and will be removed in a future release, use json::value::at() instead.")
631 value
get(
size_t index) const;
638 _ASYNCRTIMP value & operator [] (
size_t index);
641 friend class
web::json::details::_Object;
642 friend class
web::json::details::_Array;
643 template<typename CharType> friend class
web::json::details::JSON_Parser;
646 _ASYNCRTIMP
void format(std::basic_string<utf16char> &
string)
const;
652 _ASYNCRTIMP
void format(std::basic_string<char>&
string)
const;
658 #ifdef ENABLE_JSON_VALUE_VISUALIZER
659 explicit value(std::unique_ptr<details::_Value> v,
value_type kind) : m_value(std::move(v)), m_kind(kind)
661 explicit value(std::unique_ptr<details::_Value> v) : m_value(std::move(v))
665 std::unique_ptr<details::_Value> m_value;
666 #ifdef ENABLE_JSON_VALUE_VISUALIZER
678 std::string _message;
683 const char* what()
const CPPREST_NOEXCEPT
685 return _message.c_str();
693 left_over_character_in_stream = 1,
694 malformed_array_literal,
697 malformed_object_literal,
698 malformed_numeric_literal,
699 malformed_string_literal,
709 virtual const char* name()
const CPPREST_NOEXCEPT
override
714 virtual std::string message(
int ev)
const override
718 case json_error::left_over_character_in_stream:
719 return "Left-over characters in stream after parsing a JSON value";
720 case json_error::malformed_array_literal:
721 return "Malformed array literal";
722 case json_error::malformed_comment:
723 return "Malformed comment";
724 case json_error::malformed_literal:
725 return "Malformed literal";
726 case json_error::malformed_object_literal:
727 return "Malformed object literal";
728 case json_error::malformed_numeric_literal:
729 return "Malformed numeric literal";
730 case json_error::malformed_string_literal:
731 return "Malformed string literal";
732 case json_error::malformed_token:
733 return "Malformed token";
734 case json_error::mismatched_brances:
735 return "Mismatched braces";
736 case json_error::nesting:
737 return "Nesting too deep";
738 case json_error::unexpected_token:
739 return "Unexpected token";
741 return "Unknown json error";
754 typedef std::vector<json::value> storage_type;
757 typedef storage_type::iterator iterator;
758 typedef storage_type::const_iterator const_iterator;
759 typedef storage_type::reverse_iterator reverse_iterator;
760 typedef storage_type::const_reverse_iterator const_reverse_iterator;
761 typedef storage_type::size_type size_type;
764 array() : m_elements() { }
765 array(size_type
size) : m_elements(size) { }
766 array(storage_type elements) : m_elements(std::move(elements)) { }
775 return m_elements.begin();
784 return m_elements.cbegin();
793 return m_elements.end();
800 const_iterator
end()
const
802 return m_elements.cend();
811 return m_elements.rbegin();
820 return m_elements.rbegin();
829 return m_elements.rend();
836 const_reverse_iterator
rend()
const
838 return m_elements.crend();
847 return m_elements.cbegin();
856 return m_elements.cend();
865 return m_elements.crbegin();
872 const_reverse_iterator
crend()
const
874 return m_elements.crend();
885 return m_elements.erase(position);
894 if (index >= m_elements.size())
898 m_elements.erase(m_elements.begin() + index);
908 if (index >= m_elements.size())
911 return m_elements[index];
921 if (index >= m_elements.size())
924 return m_elements[index];
937 if (nlastSize < nMinSize)
938 m_elements.resize(nMinSize);
940 return m_elements[index];
949 return m_elements.size();
953 storage_type m_elements;
964 typedef std::vector<std::pair<utility::string_t, json::value>> storage_type;
967 typedef storage_type::iterator iterator;
968 typedef storage_type::const_iterator const_iterator;
969 typedef storage_type::reverse_iterator reverse_iterator;
970 typedef storage_type::const_reverse_iterator const_reverse_iterator;
971 typedef storage_type::size_type size_type;
974 object(
bool keep_order =
false) : m_elements(), m_keep_order(keep_order) { }
975 object(storage_type elements,
bool keep_order =
false) : m_elements(std::move(elements)), m_keep_order(keep_order)
978 sort(m_elements.begin(), m_elements.end(), compare_pairs);
989 return m_elements.begin();
998 return m_elements.cbegin();
1007 return m_elements.end();
1016 return m_elements.cend();
1025 return m_elements.rbegin();
1034 return m_elements.rbegin();
1043 return m_elements.rend();
1050 const_reverse_iterator
rend()
const
1052 return m_elements.crend();
1061 return m_elements.cbegin();
1070 return m_elements.cend();
1079 return m_elements.crbegin();
1088 return m_elements.crend();
1099 return m_elements.erase(position);
1106 void erase(
const utility::string_t &key)
1108 auto iter = find_by_key(key);
1109 if (iter == m_elements.end())
1114 m_elements.erase(iter);
1124 auto iter = find_by_key(key);
1125 if (iter == m_elements.end())
1130 return iter->second;
1140 auto iter = find_by_key(key);
1141 if (iter == m_elements.end())
1146 return iter->second;
1156 auto iter = find_insert_location(key);
1158 if (iter == m_elements.end() || key != iter->first)
1160 return m_elements.insert(iter, std::pair<utility::string_t, value>(key, value()))->second;
1163 return iter->second;
1171 const_iterator
find(
const utility::string_t& key)
const
1173 return find_by_key(key);
1182 return m_elements.size();
1191 return m_elements.empty();
1195 static bool compare_pairs(
const std::pair<utility::string_t, value>& p1,
const std::pair<utility::string_t, value>& p2)
1197 return p1.first < p2.first;
1199 static bool compare_with_key(
const std::pair<utility::string_t, value>& p1,
const utility::string_t& key)
1201 return p1.first < key;
1204 storage_type::iterator find_insert_location(
const utility::string_t &key)
1208 return std::find_if(m_elements.begin(), m_elements.end(),
1209 [&key](
const std::pair<utility::string_t, value>& p) {
1210 return p.first == key;
1215 return std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
1219 storage_type::const_iterator find_by_key(
const utility::string_t& key)
const
1223 return std::find_if(m_elements.begin(), m_elements.end(),
1224 [&key](
const std::pair<utility::string_t, value>& p) {
1225 return p.first == key;
1230 auto iter = std::lower_bound(m_elements.begin(), m_elements.end(), key, compare_with_key);
1231 if (iter != m_elements.end() && key != iter->first)
1233 return m_elements.end();
1239 storage_type::iterator find_by_key(
const utility::string_t& key)
1241 auto iter = find_insert_location(key);
1242 if (iter != m_elements.end() && key != iter->first)
1244 return m_elements.end();
1249 storage_type m_elements;
1251 friend class details::_Object;
1253 template<
typename CharType>
friend class json::details::JSON_Parser;
1264 number(
double value) : m_value(value), m_type(double_type) { }
1265 number(int32_t value) : m_intval(value), m_type(value < 0 ? signed_type : unsigned_type) { }
1266 number(uint32_t value) : m_intval(value), m_type(unsigned_type) { }
1267 number(int64_t value) : m_intval(value), m_type(value < 0 ? signed_type : unsigned_type) { }
1268 number(uint64_t value) : m_uintval(value), m_type(unsigned_type) { }
1298 case signed_type :
return m_intval >= 0;
1299 case unsigned_type :
return true;
1314 case double_type :
return m_value;
1315 case signed_type :
return static_cast<double>(m_intval);
1316 case unsigned_type :
return static_cast<double>(m_uintval);
1317 default :
return false;
1327 if (m_type == double_type)
1328 return static_cast<int32_t
>(m_value);
1330 return static_cast<int32_t
>(m_intval);
1339 if (m_type == double_type)
1340 return static_cast<uint32_t
>(m_value);
1342 return static_cast<uint32_t
>(m_intval);
1351 if (m_type == double_type)
1352 return static_cast<int64_t
>(m_value);
1354 return static_cast<int64_t
>(m_intval);
1363 if (m_type == double_type)
1364 return static_cast<uint64_t
>(m_value);
1366 return static_cast<uint64_t
>(m_intval);
1375 return m_type != double_type;
1385 if (m_type != other.m_type)
1390 case json::number::type::signed_type :
1391 return m_intval == other.m_intval;
1392 case json::number::type::unsigned_type :
1393 return m_uintval == other.m_uintval;
1394 case json::number::type::double_type :
1395 return m_value == other.m_value;
1410 signed_type=0, unsigned_type, double_type
1413 friend class details::_Number;
1421 virtual std::unique_ptr<_Value> _copy_value() = 0;
1423 virtual bool has_field(
const utility::string_t &)
const {
return false; }
1424 virtual value get_field(
const utility::string_t &)
const {
throw json_exception(_XPLATSTR(
"not an object")); }
1425 virtual value get_element(array::size_type)
const {
throw json_exception(_XPLATSTR(
"not an array")); }
1427 virtual value &index(
const utility::string_t &) {
throw json_exception(_XPLATSTR(
"not an object")); }
1428 virtual value &index(array::size_type) {
throw json_exception(_XPLATSTR(
"not an array")); }
1430 virtual const value &cnst_index(
const utility::string_t &)
const {
throw json_exception(_XPLATSTR(
"not an object")); }
1431 virtual const value &cnst_index(array::size_type)
const {
throw json_exception(_XPLATSTR(
"not an array")); }
1434 virtual void serialize_impl(std::string& str)
const
1439 virtual void serialize_impl(std::wstring& str)
const
1445 virtual utility::string_t to_string()
const
1447 utility::string_t str;
1448 serialize_impl(str);
1454 virtual bool is_integer()
const {
throw json_exception(_XPLATSTR(
"not a number")); }
1455 virtual bool is_double()
const {
throw json_exception(_XPLATSTR(
"not a number")); }
1458 virtual double as_double()
const {
throw json_exception(_XPLATSTR(
"not a number")); }
1459 virtual int as_integer()
const {
throw json_exception(_XPLATSTR(
"not a number")); }
1460 virtual bool as_bool()
const {
throw json_exception(_XPLATSTR(
"not a boolean")); }
1465 virtual const utility::string_t& as_string()
const {
throw json_exception(_XPLATSTR(
"not a string")); }
1467 virtual size_t size()
const {
return 0; }
1474 virtual void format(std::basic_string<char>& stream)
const
1476 stream.append(
"null");
1479 virtual void format(std::basic_string<wchar_t>& stream)
const
1481 stream.append(L
"null");
1492 virtual std::unique_ptr<_Value> _copy_value()
1494 return utility::details::make_unique<_Null>();
1502 _Number(
double value) : m_number(value) { }
1503 _Number(int32_t value) : m_number(value) { }
1504 _Number(uint32_t value) : m_number(value) { }
1505 _Number(int64_t value) : m_number(value) { }
1506 _Number(uint64_t value) : m_number(value) { }
1508 virtual std::unique_ptr<_Value> _copy_value()
1510 return utility::details::make_unique<_Number>(*this);
1515 virtual bool is_integer()
const {
return m_number.
is_integral(); }
1516 virtual bool is_double()
const {
return !m_number.
is_integral(); }
1518 virtual double as_double()
const
1523 virtual int as_integer()
const
1528 virtual const number& as_number() {
return m_number; }
1531 virtual void format(std::basic_string<char>& stream)
const ;
1533 virtual void format(std::basic_string<wchar_t>& stream)
const;
1544 _Boolean(
bool value) : m_value(value) { }
1546 virtual std::unique_ptr<_Value> _copy_value()
1548 return utility::details::make_unique<_Boolean>(*this);
1553 virtual bool as_bool()
const {
return m_value; }
1556 virtual void format(std::basic_string<char>& stream)
const
1558 stream.append(m_value ?
"true" :
"false");
1562 virtual void format(std::basic_string<wchar_t>& stream)
const
1564 stream.append(m_value ? L
"true" : L
"false");
1576 _String(utility::string_t value) : m_string(std::move(value))
1578 m_has_escape_char = has_escape_chars(*
this);
1580 _String(utility::string_t value,
bool escaped_chars)
1581 : m_string(std::move(value)),
1582 m_has_escape_char(escaped_chars)
1588 m_has_escape_char = has_escape_chars(*
this);
1590 _String(std::string &&value,
bool escape_chars)
1592 m_has_escape_char(escape_chars)
1596 virtual std::unique_ptr<_Value> _copy_value()
1598 return utility::details::make_unique<_String>(*this);
1603 virtual const utility::string_t & as_string()
const;
1605 virtual void serialize_impl(std::string& str)
const
1607 serialize_impl_char_type(str);
1610 virtual void serialize_impl(std::wstring& str)
const
1612 serialize_impl_char_type(str);
1617 virtual void format(std::basic_string<char>& str)
const;
1619 virtual void format(std::basic_string<wchar_t>& str)
const;
1626 size_t get_reserve_size()
const
1628 return m_string.size() + 2;
1631 template <
typename CharType>
1632 void serialize_impl_char_type(std::basic_string<CharType>& str)
const
1636 str.reserve(get_reserve_size());
1640 std::string as_utf8_string()
const;
1641 utf16string as_utf16_string()
const;
1643 utility::string_t m_string;
1647 bool m_has_escape_char;
1648 static bool has_escape_chars(
const _String &str);
1651 template<
typename CharType>
1652 _ASYNCRTIMP
void append_escape_string(std::basic_string<CharType>& str,
const std::basic_string<CharType>& escaped);
1654 void format_string(
const utility::string_t& key, utility::string_t& str);
1657 void format_string(
const utility::string_t& key, std::string& str);
1664 _Object(
bool keep_order) : m_object(keep_order) { }
1665 _Object(object::storage_type fields,
bool keep_order) : m_object(std::move(fields), keep_order) { }
1667 virtual std::unique_ptr<_Value> _copy_value()
1669 return utility::details::make_unique<_Object>(*this);
1674 virtual const json::object& as_object()
const {
return m_object; }
1678 virtual bool has_field(
const utility::string_t &)
const;
1680 virtual json::value &index(
const utility::string_t &key);
1682 bool is_equal(
const _Object* other)
const
1684 if (m_object.
size() != other->m_object.
size())
1687 return std::equal(std::begin(m_object), std::end(m_object), std::begin(other->m_object));
1690 virtual void serialize_impl(std::string& str)
const
1693 str.reserve(get_reserve_size());
1697 virtual void serialize_impl(std::wstring& str)
const
1700 str.reserve(get_reserve_size());
1704 size_t size()
const {
return m_object.
size(); }
1707 virtual void format(std::basic_string<char>& str)
const
1712 virtual void format(std::basic_string<wchar_t>& str)
const
1723 template<
typename CharType>
1724 void format_impl(std::basic_string<CharType>& str)
const
1727 if(!m_object.
empty())
1729 auto lastElement = m_object.
end() - 1;
1730 for (
auto iter = m_object.
begin(); iter != lastElement; ++iter)
1732 format_string(iter->first, str);
1734 iter->second.format(str);
1737 format_string(lastElement->first, str);
1739 lastElement->second.format(str);
1744 size_t get_reserve_size()
const
1749 size_t reserveSize = 2;
1750 for(
auto iter = m_object.
begin(); iter != m_object.
end(); ++iter)
1752 reserveSize += iter->first.length() + 2;
1753 size_t valueSize = iter->second.size() * 20;
1758 valueSize =
static_cast<_String *
>(iter->second.m_value.get())->get_reserve_size();
1765 reserveSize += valueSize;
1775 _Array(array::size_type size) : m_array(size) {}
1776 _Array(array::storage_type elements) : m_array(std::move(elements)) { }
1778 virtual std::unique_ptr<_Value> _copy_value()
1780 return utility::details::make_unique<_Array>(*this);
1785 virtual json::array& as_array() {
return m_array; }
1786 virtual const json::array& as_array()
const {
return m_array; }
1788 virtual json::value &index(json::array::size_type index)
1790 return m_array[index];
1793 bool is_equal(
const _Array* other)
const
1795 if ( m_array.
size() != other->m_array.
size())
1798 auto iterT = m_array.
cbegin();
1799 auto iterO = other->m_array.
cbegin();
1800 auto iterTe = m_array.
cend();
1801 auto iterOe = other->m_array.
cend();
1803 for (; iterT != iterTe && iterO != iterOe; ++iterT, ++iterO)
1805 if ( *iterT != *iterO )
1812 virtual void serialize_impl(std::string& str)
const
1815 str.reserve(get_reserve_size());
1819 virtual void serialize_impl(std::wstring& str)
const
1822 str.reserve(get_reserve_size());
1826 size_t size()
const {
return m_array.
size(); }
1829 virtual void format(std::basic_string<char>& str)
const
1834 virtual void format(std::basic_string<wchar_t>& str)
const
1844 template<
typename CharType>
1845 void format_impl(std::basic_string<CharType>& str)
const
1848 if(!m_array.m_elements.empty())
1850 auto lastElement = m_array.m_elements.end() - 1;
1851 for (
auto iter = m_array.m_elements.begin(); iter != lastElement; ++iter)
1856 lastElement->format(str);
1861 size_t get_reserve_size()
const
1865 size_t reserveSize = 2;
1866 for(
auto iter = m_array.
cbegin(); iter != m_array.
cend(); ++iter)
1868 size_t valueSize = iter->size() * 20;
1873 reserveSize += valueSize;
1886 return m_value->size();
1896 return m_value->has_field(key);
1906 return m_value->get_field(key);
1916 return m_value->get_element(index);
1925 _ASYNCRTIMP utility::ostream_t& __cdecl
operator << (utility::ostream_t &os,
const json::value &val);
1933 _ASYNCRTIMP utility::istream_t& __cdecl
operator >> (utility::istream_t &is, json::value &val);
bool operator==(const number &other) const
Compares two JSON numbers for equality.
Definition: json.h:1383
bool is_integral() const
Is the number represented internally as an integral type?
Definition: json.h:1373
A JSON array represented as a C++ class.
Definition: json.h:752
Boolean value.
Definition: json.h:94
_ASYNCRTIMP bool is_uint32() const
Does the number fit into unsigned int32?
Number value.
Definition: json.h:92
int32_t to_int32() const
Converts the JSON number to int32.
Definition: json.h:1325
const_reverse_iterator crbegin() const
Gets the beginning const reverse iterator element of the object.
Definition: json.h:1077
json::value & operator[](size_type index)
Accesses an element of a JSON array.
Definition: json.h:932
static _ASYNCRTIMP json::value __cdecl object(bool keep_order=false)
Creates an object value
value get(const utility::string_t &key) const
Accesses a field of a JSON object.
const json::value & at(size_type index) const
Accesses an element of a JSON array. Throws when index out of bounds.
Definition: json.h:919
reverse_iterator rbegin()
Gets the beginning reverse iterator element of the object
Definition: json.h:1023
Object value.
Definition: json.h:98
void erase(const utility::string_t &key)
Deletes an element of the JSON object. If the key doesn't exist, this method throws.
Definition: json.h:1106
const_iterator end() const
Gets the end const iterator element of the object.
Definition: json.h:1014
size_type size() const
Gets the number of elements of the array.
Definition: json.h:947
_ASYNCRTIMP int as_integer() const
Converts the JSON value to a C++ integer, if and only if it is a number value. Throws json_exception ...
const_iterator cend() const
Gets the end const iterator element of the array.
Definition: json.h:854
_ASYNCRTIMP bool is_int64() const
Does the number fit into int64?
bool has_field(const utility::string_t &key) const
Tests for the presence of a field.
Definition: json.h:1894
iterator begin()
Gets the beginning iterator element of the object
Definition: json.h:987
Null value.
Definition: json.h:102
const_reverse_iterator crend() const
Gets the end const reverse iterator element of the object.
Definition: json.h:1086
bool is_string() const
Is the current value a string value?
Definition: json.h:386
bool is_number() const
Is the current value a number value?
Definition: json.h:354
_ASYNCRTIMP json::array & as_array()
Converts the JSON value to a json array, if and only if it is an array value.
reverse_iterator rend()
Gets the end reverse iterator element of the array
Definition: json.h:827
A JSON number represented as a C++ class.
Definition: json.h:1259
uint64_t to_uint64() const
Converts the JSON number to unsigned int64.
Definition: json.h:1361
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
_ASYNCRTIMP json::object & as_object()
Converts the JSON value to a json object, if and only if it is an object value.
const_iterator find(const utility::string_t &key) const
Gets an iterator to an element of a JSON object.
Definition: json.h:1171
bool is_null() const
Is the current value a null value?
Definition: json.h:348
value_type
This enumeration represents the various kinds of JSON values.
Definition: json.h:89
_ASYNCRTIMP bool as_bool() const
Converts the JSON value to a C++ bool, if and only if it is a Boolean value.
bool is_array() const
Is the current value an array?
Definition: json.h:392
iterator erase(iterator position)
Deletes an element of the JSON array.
Definition: json.h:883
size_t size() const
Gets the number of children of the value.
Definition: json.h:1884
iterator begin()
Gets the beginning iterator element of the array
Definition: json.h:773
_ASYNCRTIMP utility::ostream_t &__cdecl operator<<(utility::ostream_t &os, const json::value &val)
A standard std::ostream operator to facilitate writing JSON values to streams.
iterator end()
Gets the end iterator element of the array
Definition: json.h:791
bool is_uint64() const
Does the number fit into unsigned int64?
Definition: json.h:1294
_ASYNCRTIMP utility::string_t serialize() const
Serializes the current JSON value to a C++ string.
_ASYNCRTIMP utility::string_t __cdecl to_string_t(std::string &&s)
Converts to a platform dependent Unicode string type.
const_iterator cbegin() const
Gets the beginning const iterator element of the object.
Definition: json.h:1059
const_reverse_iterator crend() const
Gets the end const reverse iterator element of the array.
Definition: json.h:872
const_reverse_iterator rend() const
Gets the end const reverse iterator element of the object
Definition: json.h:1050
reverse_iterator rend()
Gets the end reverse iterator element of the object
Definition: json.h:1041
bool operator!=(const value &other) const
Compares two JSON values for inequality.
Definition: json.h:547
bool empty() const
Checks if there are any elements in the JSON object.
Definition: json.h:1189
_ASYNCRTIMP bool is_int32() const
Does the number fit into int32?
_ASYNCRTIMP utf16string __cdecl to_utf16string(const std::string &value)
Converts to a UTF-16 from string.
json::value & operator[](const utility::string_t &key)
Accesses an element of a JSON object.
Definition: json.h:1154
const json::value & at(const utility::string_t &key) const
Accesses an element of a JSON object. If the key doesn't exist, this method throws.
Definition: json.h:1138
_ASYNCRTIMP json::value & at(size_t index)
Accesses an element of a JSON array. Throws when index out of bounds.
void _ASYNCRTIMP __cdecl keep_object_element_order(bool keep_order)
Preserve the order of the name/value pairs when parsing a JSON object. The default is false...
static _ASYNCRTIMP value __cdecl parse(const utility::string_t &value)
Parses a string and construct a JSON value.
const_reverse_iterator rbegin() const
Gets the beginning const reverse iterator element of the array
Definition: json.h:818
reverse_iterator rbegin()
Gets the beginning reverse iterator element of the array
Definition: json.h:809
bool is_boolean() const
Is the current value a Boolean value?
Definition: json.h:380
A JSON object represented as a C++ class.
Definition: json.h:962
iterator erase(iterator position)
Deletes an element of the JSON object.
Definition: json.h:1097
const_iterator begin() const
Gets the beginning const iterator element of the array.
Definition: json.h:782
_ASYNCRTIMP bool is_integer() const
Is the current value represented as an integer number value?
A JSON value represented as a C++ class.
Definition: json.h:83
static _ASYNCRTIMP value __cdecl null()
Creates a null value
A single exception type to represent errors in parsing, converting, and accessing elements of JSON va...
Definition: json.h:675
const_reverse_iterator rend() const
Gets the end const reverse iterator element of the array
Definition: json.h:836
const_iterator end() const
Gets the end const iterator element of the array.
Definition: json.h:800
static _ASYNCRTIMP value __cdecl string(utility::string_t value)
Creates a string value
bool is_object() const
Is the current value an object?
Definition: json.h:398
static _ASYNCRTIMP json::value __cdecl array()
Creates an empty JSON array
_ASYNCRTIMP double as_double() const
Converts the JSON value to a C++ double, if and only if it is a number value. Throws json_exception i...
const_reverse_iterator crbegin() const
Gets the beginning const reverse iterator element of the array.
Definition: json.h:863
iterator end()
Gets the end iterator element of the object
Definition: json.h:1005
const_iterator cend() const
Gets the end const iterator element of the object.
Definition: json.h:1068
json::value & at(size_type index)
Accesses an element of a JSON array. Throws when index out of bounds.
Definition: json.h:906
_ASYNCRTIMP utility::istream_t &__cdecl operator>>(utility::istream_t &is, json::value &val)
A standard std::istream operator to facilitate reading JSON values from streams.
double to_double() const
Converts the JSON number to a C++ double.
Definition: json.h:1310
_ASYNCRTIMP bool is_double() const
Is the current value represented as an double number value?
String value.
Definition: json.h:96
_ASYNCRTIMP json::value::value_type type() const
Accesses the type of JSON value the current value instance is
_ASYNCRTIMP const json::number & as_number() const
Converts the JSON value to a number class, if and only if it is a number value. Throws json_exception...
_ASYNCRTIMP bool operator==(const value &other) const
Compares two JSON values for equality.
_ASYNCRTIMP value & operator[](const utility::string_t &key)
Accesses a field of a JSON object.
size_type size() const
Gets the number of elements of the object.
Definition: json.h:1180
_ASYNCRTIMP value()
Constructor creating a null value
Array value.
Definition: json.h:100
Definition: SafeInt3.hpp:5564
uint32_t to_uint32() const
Converts the JSON number to unsigned int32.
Definition: json.h:1337
_ASYNCRTIMP std::string __cdecl to_utf8string(std::string value)
Converts to a UTF-8 string.
Various utilities for string conversions and date and time manipulation.
Definition: asyncrt_utils.h:50
int64_t to_int64() const
Converts the JSON number to int64.
Definition: json.h:1349
_ASYNCRTIMP void erase(size_t index)
Erases an element of a JSON array. Throws if index is out of bounds.
const_iterator cbegin() const
Gets the beginning const iterator element of the array.
Definition: json.h:845
json::value & at(const utility::string_t &key)
Accesses an element of a JSON object. If the key doesn't exist, this method throws.
Definition: json.h:1122
_ASYNCRTIMP const utility::string_t & as_string() const
Converts the JSON value to a C++ STL string, if and only if it is a string value. ...
const_reverse_iterator rbegin() const
Gets the beginning const reverse iterator element of the object
Definition: json.h:1032
const_iterator begin() const
Gets the beginning const iterator element of the object.
Definition: json.h:996
void erase(size_type index)
Deletes the element at an index of the JSON array.
Definition: json.h:892