Inherits JsonStatics.
|
|
const char * | class_name () const |
| |
| | Json () |
| | Construct a null Json.
|
| |
| | Json (const uninitialized_t &) |
| | Construct an uninitialized timestamp.
|
| |
| | Json (const Json &x) |
| | Construct a Json copy of x.
|
| |
| | Json (int x) |
| | Construct simple Json values.
|
| |
|
| Json (unsigned x) |
| |
|
| Json (long x) |
| |
|
| Json (unsigned long x) |
| |
|
| Json (double x) |
| |
|
| Json (bool x) |
| |
|
| Json (const String &x) |
| |
|
| Json (const char *x) |
| |
| template<typename T > |
| | Json (const Vector< T > &x) |
| | Construct an array Json containing the elements of x.
|
| |
| template<typename T > |
| | Json (T first, T last) |
| | Construct an array Json containing the elements in [first, last).
|
| |
| template<typename T > |
| | Json (const HashTable< String, T > &x) |
| | Construct an object Json containing the values in x.
|
| |
| | operator unspecified_bool_type () const |
| | Return true if this Json is not null.
|
| |
| bool | operator! () const |
| | Return true if this Json is null.
|
| |
| json_type | type () const |
| | Return this Json's type.
|
| |
| bool | is_null () const |
| | Test this Json's type.
|
| |
|
bool | is_int () const |
| |
|
bool | is_double () const |
| |
|
bool | is_number () const |
| |
|
bool | is_bool () const |
| |
|
bool | is_string () const |
| |
|
bool | is_array () const |
| |
|
bool | is_object () const |
| |
| bool | is_primitive () const |
| | Test if this Json is a primitive value, not including null.
|
| |
| bool | empty () const |
| | Return true if this Json is null, an empty array, or an empty object.
|
| |
| size_type | size () const |
| | Return the number of elements in this complex Json.
|
| |
| long | to_i () const |
| | Return this Json converted to an integer.
|
| |
| uint64_t | to_u64 () const |
| | Return this Json converted to a 64-bit unsigned integer.
|
| |
| bool | to_i (int &x) const |
| | Extract this integer Json's value into x.
|
| |
| bool | to_i (unsigned &x) const |
| |
| bool | to_i (long &x) const |
| |
| bool | to_i (unsigned long &x) const |
| |
| long | as_i () const |
| | Return the integer value of this numeric Json.
|
| |
| double | to_d () const |
| | Return this Json converted to a double.
|
| |
| bool | to_d (double &x) const |
| | Extract this numeric Json's value into x.
|
| |
| double | as_d () const |
| | Return the double value of this numeric Json.
|
| |
| bool | to_b () const |
| | Return this Json converted to a boolean.
|
| |
| bool | to_b (bool &x) const |
| | Extract this boolean Json's value into x.
|
| |
| bool | as_b () const |
| | Return the value of this boolean Json.
|
| |
| const String & | to_s () const |
| | Return this Json converted to a string.
|
| |
| bool | to_s (String &x) const |
| | Extract this string Json's value into x.
|
| |
| const String & | as_s () const |
| | Return the value of this string Json.
|
| |
| const char * | c_str () const |
| | Return to_s().c_str().
|
| |
| size_type | count (const StringRef &key) const |
| | Return 1 if this object Json contains key, 0 otherwise.
|
| |
| const Json & | get (const StringRef &key) const |
| | Return the value at key in an object or array Json.
|
| |
| Json & | get_insert (const String &key) |
| | Return a reference to the value of key in an object Json.
|
| |
| Json & | get_insert (const StringRef &key) |
| |
| Json & | get_insert (const char *key) |
| |
| long | get_i (const StringRef &key) const |
| | Return get(key).to_i().
|
| |
| double | get_d (const StringRef &key) const |
| | Return get(key).to_d().
|
| |
| bool | get_b (const StringRef &key) const |
| | Return get(key).to_b().
|
| |
| const String & | get_s (const StringRef &key) const |
| | Return get(key).to_s().
|
| |
| const Json_get_proxy | get (const StringRef &key, Json &x) const |
| | Extract this object Json's value at key into x.
|
| |
| const Json_get_proxy | get (const StringRef &key, int &x) const |
| |
| const Json_get_proxy | get (const StringRef &key, unsigned &x) const |
| |
| const Json_get_proxy | get (const StringRef &key, long &x) const |
| |
| const Json_get_proxy | get (const StringRef &key, unsigned long &x) const |
| |
| const Json_get_proxy | get (const StringRef &key, double &x) const |
| |
| const Json_get_proxy | get (const StringRef &key, bool &x) const |
| |
| const Json_get_proxy | get (const StringRef &key, String &x) const |
| |
| const Json & | operator[] (const StringRef &key) const |
| | Return the value at key in an object or array Json.
|
| |
| Json_object_proxy< Json > | operator[] (const String &key) |
| | Return a proxy reference to the value at key in an object Json.
|
| |
| Json_object_str_proxy< Json > | operator[] (const StringRef &key) |
| |
| Json_object_str_proxy< Json > | operator[] (const char *key) |
| |
| const Json & | at (const StringRef &key) const |
| | Return the value at key in an object Json.
|
| |
| Json & | at_insert (const String &key) |
| | Return a reference to the value at key in an object Json.
|
| |
| Json & | at_insert (const StringRef &key) |
| |
| Json & | at_insert (const char *key) |
| |
| template<typename T > |
| Json & | set (const String &key, T value) |
| | Set the value of key to value in this object Json.
|
| |
| Json & | unset (const StringRef &key) |
| | Remove the value of key from an object Json.
|
| |
| Pair< object_iterator, bool > | insert (const object_value_type &x) |
| | Insert element x in this object Json.
|
| |
| object_iterator | insert (object_iterator position, const object_value_type &x) |
| | Insert element x in this object Json.
|
| |
| size_type | erase (const StringRef &key) |
| | Remove the value of key from an object Json.
|
| |
| Json & | merge (const Json &x) |
| | Merge the values of object Json x into this object Json.
|
| |
|
template<typename P > |
| Json & | merge (const Json_proxy_base< P > &x) |
| |
| const Json & | get (size_type x) const |
| | Return the x th array element.
|
| |
| Json & | get_insert (size_type x) |
| | Return a reference to the x th array element.
|
| |
| const Json & | operator[] (size_type x) const |
| | Return the x th array element.
|
| |
| Json_array_proxy< Json > | operator[] (size_type x) |
| | Return a proxy reference to the x th array element.
|
| |
| const Json & | at (size_type x) const |
| | Return the x th element in an array Json.
|
| |
| Json & | at_insert (size_type x) |
| | Return a reference to the x th element in an array Json.
|
| |
| const Json & | back () const |
| | Return the last array element.
|
| |
| Json & | back () |
| | Return a reference to the last array element.
|
| |
| template<typename T > |
| Json & | push_back (T x) |
| | Push an element onto the back of the array.
|
| |
| void | pop_back () |
| | Remove the last element from an array.
|
| |
|
const_object_iterator | obegin () const |
| |
|
const_object_iterator | oend () const |
| |
|
object_iterator | obegin () |
| |
|
object_iterator | oend () |
| |
|
const_object_iterator | cobegin () const |
| |
|
const_object_iterator | coend () const |
| |
|
const_array_iterator | abegin () const |
| |
|
const_array_iterator | aend () const |
| |
|
array_iterator | abegin () |
| |
|
array_iterator | aend () |
| |
|
const_array_iterator | cabegin () const |
| |
|
const_array_iterator | caend () const |
| |
|
const_iterator | begin () const |
| |
|
const_iterator | end () const |
| |
|
iterator | begin () |
| |
|
iterator | end () |
| |
|
const_iterator | cbegin () const |
| |
|
const_iterator | cend () const |
| |
| String | unparse () const |
| | Return the string representation of this Json.
|
| |
| String | unparse (bool add_newline) const |
| | Return the string representation of this Json.
|
| |
| String | unparse (const unparse_manipulator &m, bool add_newline=false) const |
| | Return the string representation of this Json.
|
| |
| void | unparse (StringAccum &sa) const |
| | Unparse the string representation of this Json into sa.
|
| |
| void | unparse (StringAccum &sa, const unparse_manipulator &m) const |
| | Unparse the string representation of this Json into sa.
|
| |
| bool | assign_parse (const String &str) |
| | Parse str as UTF-8 JSON into this Json object.
|
| |
| bool | assign_parse (const char *first, const char *last) |
| | Parse [first, last) as UTF-8 JSON into this Json object.
|
| |
|
Json & | operator= (const Json &x) |
| |
|
template<typename P > |
| Json & | operator= (const Json_proxy_base< P > &x) |
| |
| Json & | operator++ () |
| |
|
void | operator++ (int) |
| |
|
Json & | operator-- () |
| |
|
void | operator-- (int) |
| |
|
Json & | operator+= (int x) |
| |
|
Json & | operator+= (long x) |
| |
|
Json & | operator+= (double x) |
| |
| void | swap (Json &x) |
| | Swap this Json with x.
|
| |
|
| JsonStatics () |
| |
Json data.
The Json class represents Json data: null values, booleans, numbers, strings, and combinations of these primitives into arrays and objects.
Json objects are not references, and two Json values cannot share subobjects. This differs from Javascript. For example:
Json j1 = Json::make_object(), j2 = Json::make_object(); j1.set("a", j2); // stores a COPY of j2 in j1 j2.set("b", 1); assert(j1.unparse() == "{\"a\":{}}"); assert(j2.unparse() == "{\"b\":1}");
Compare this with the Javascript code:
var j1 = {}, j2 = {}; j1.a = j2; // stores a REFERENCE to j2 in j1 j2.b = 1; assert(JSON.stringify(j1) == "{\"a\":{\"b\":1}}");
Most Json functions for extracting components and typed values behave liberally. For example, objects silently convert to integers, and extracting properties from non-objects is allowed. This should make it easier to work with untrusted objects. (Json objects often originate from untrusted sources, and may not have the types you expect.) If you prefer an assertion to fail when a Json object has an unexpected type, use the checked as_ and at functions, rather than the liberal to_, get, and operator[] functions.
| const Json_get_proxy Json::get |
( |
const StringRef & |
key, |
|
|
Json & |
x |
|
) |
| const |
|
inline |
Extract this object Json's value at key into x.
- Parameters
-
- Returns
- proxy for *this
x is assigned iff contains(key). The return value is a proxy object that mostly behaves like *this. However, the proxy is "truthy" iff contains(key) and x was assigned. The proxy also has status() methods that return the extraction status. For example:
Json j = Json::parse("{\"a\":1,\"b\":2}"), x; assert(j.get("a", x)); // extraction succeeded assert(x == Json(1)); assert(!j.get("c", x)); // no "c" key assert(x == Json(1)); // x remains unchanged assert(!j.get("c", x).status()); // can use ".status()" for clarity
Can chain .get() methods to extract multiple values Json a, b, c; j.get("a", a).get("b", b); assert(a == Json(1) && b == Json(2));
Use .status() to return or assign extraction status bool a_status, b_status, c_status; j.get("a", a).status(a_status) .get("b", b).status(b_status) .get("c", c).status(c_status); assert(a_status && b_status && !c_status);
Overloaded versions of get() can extract integer, double, boolean, and string values for specific keys. These versions succeed iff contains(key) and the corresponding value has the expected type. For example:
Json j = Json::parse("{\"a\":1,\"b\":\"\"}"); int a, b; bool a_status, b_status; j.get("a", a).status(a_status).get("b", b).status(b_status); assert(a_status && a == 1 && !b_status);