provides a wrapper over JSON libraries. Corelink supports a wrapper over RapidJSON, however, if the interface is maintained, another JSON library can be wrapped and used More...
#include <json.hpp>
Public Member Functions | |
| json (bool root_type_array=false) | |
| json (in< std::string > json_str) | |
| json (rvref< json > rhs) noexcept | |
| Move constructor. | |
| json & | operator= (rvref< json > rhs) noexcept |
| Move assignment operator. | |
| json & | operator= (clvref< json > rhs) |
| Copy assignment operator. | |
| json (clvref< json > rhs) | |
| Copy constructor. | |
| ~json ()=default | |
| rapidjson::Document & | operator() () |
| () operator overload. | |
| clvref< rapidjson::Document > | operator() () const |
| () operator overload for const objects | |
| int32_t | get_int (in< std::string > name, int32_t def_val=0) const |
| get the value associated with the key as an integer. Note that this function can throw if the underlying value is non-convertible to an integral type | |
| int64_t | get_int64 (in< std::string > name, int64_t def_val=0) const |
| get the value associated with the key as an integer. Note that this function can throw if the underlying value is non-convertible to an integral type | |
| std::string | get_str (in< std::string > name, in< std::string > def_val="") const |
| get the value associated with the key as std::string. Note that this function can throw if the underlying value is non-convertible to string type | |
| double | get_double (in< std::string > name, double def_val=0.0) const |
| get the value associated with the key as double. Note that this function can throw if the underlying value is non-convertible to floating point type | |
| bool | get_bool (in< std::string > name, bool def_val=false) const |
| get the value associated with the key as bool. Note that this function can throw if the underlying value is non-convertible to boolean type | |
| uint32_t | get_uint (in< std::string > name, uint32_t def_val=false) const |
| get the value associated with the key as an unsigned integer. Note that this function can throw if the underlying value is non-convertible to an integral type | |
| uint64_t | get_uint64 (in< std::string > name, uint64_t def_val=false) const |
| get the value associated with the key as an unsigned integer. Note that this function can throw if the underlying value is non-convertible to an integral type | |
| bool | try_parse (const std::string &json_str, std::string &error) noexcept |
| std::string | to_string (bool pretty_print=false) const |
| template<class T > | |
| json & | append (const std::vector< std::map< std::string, T > > &arr_items) |
| Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is scalar native type. | |
| json & | append (const std::vector< std::map< std::string, std::string > > &arr_items) |
| Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is string type. | |
| template<class T > | |
| json & | append (const std::vector< std::map< std::string, std::vector< T > > > &arr_items) |
| Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is an array of scalar native type values. | |
| json & | append (const std::vector< std::map< std::string, std::vector< std::string > > > &arr_items) |
| Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is an array of string type values. | |
| template<class T > | |
| json & | append (const std::string &key, const T &val) |
| Append a key value pair to the root JSON object where the value type is a native type. | |
| json & | append (const std::string &key, const std::string &val) |
| Append a key value pair to the root JSON object where the value type is a string. | |
| template<class T > | |
| json & | append (const std::string &key, const std::vector< T > &val) |
| Append a key value pair to the root JSON object where the value type is an array of native type values. | |
| json & | append (const std::string &key, const std::vector< std::string > &val) |
| Append a key value pair to the root JSON object where the value type is an array of strings. | |
| template<class T > | |
| json & | append (const std::map< std::string, T > &kv_items) |
| Append multiple key value pair to the root JSON object where the value type is a native type. | |
| json & | append (const std::map< std::string, std::string > &kv_items) |
| Append multiple key value pair to the root JSON object where the value type is value of string type. | |
| template<class T > | |
| json & | append (const std::map< std::string, std::vector< T > > &kv_items) |
| Append multiple key value pair to the root JSON object where the value type is an array of native type values. | |
| json & | append (const std::map< std::string, std::vector< std::string > > &kv_items) |
| Append multiple key value pair to the root JSON object where the value type is an array of string type values. | |
| CORELINK_CPP_ATTR_MAYBE_UNUSED json & | remove (const std::string &key) |
| CORELINK_CPP_ATTR_MAYBE_UNUSED json & | clear () |
provides a wrapper over JSON libraries. Corelink supports a wrapper over RapidJSON, however, if the interface is maintained, another JSON library can be wrapped and used
|
inlineexplicit |
Constructor
| root_type_array | if true, the default object created at the root level will be a JSON array. if false, the default object created at the root level will be a JSON object. The default value is false |
|
inlineexplicit |
Constructor
| json_str | initialize the JSON object with a JSON string |
This constructor variant will try to parse the input string as JSON. However, if the string passed is not valid JSON, it will throw
Move constructor.
| rhs | json object to move from |
Copy constructor.
| rhs | object to copy document from |
|
default |
Default destructor
|
inline |
Append multiple key value pair to the root JSON object where the value type is value of string type.
| kv_items | key value pairs that you wish to add to the root JSON object. |
|
inline |
Append multiple key value pair to the root JSON object where the value type is an array of string type values.
| kv_items | key value pairs that you wish to add to the root JSON object. |
|
inline |
Append multiple key value pair to the root JSON object where the value type is an array of native type values.
| T | native type |
| kv_items | key value pairs that you wish to add to the root JSON object. |
|
inline |
Append multiple key value pair to the root JSON object where the value type is a native type.
| T | native value type |
| kv_items | key value pairs of items to be added to the root object |
|
inline |
Append a key value pair to the root JSON object where the value type is a string.
| key | json object key |
| val | string type value |
|
inline |
Append a key value pair to the root JSON object where the value type is an array of strings.
| key | string key |
| val | array of strings |
|
inline |
Append a key value pair to the root JSON object where the value type is an array of native type values.
| native | value type |
| key | string key |
| val | array of native type values |
|
inline |
Append a key value pair to the root JSON object where the value type is a native type.
| T | native type |
| key | json object key |
| val | json object native type value |
|
inline |
Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is string type.
| arr_items | vector of key value pairs which will be appended to the root JSON |
|
inline |
Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is an array of string type values.
| arr_items | vector of key value pairs which will be appended to the root JSON |
|
inline |
Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is an array of scalar native type values.
| T | native type. please do not specify custom types here as JSON values don't support it. |
| arr_items | vector of key value pairs which will be appended to the root JSON |
|
inline |
Append multiple key-value pairs as an object to the root JSON array, where value type of each KV pair is scalar native type.
| T | native type. please do not specify custom types here as JSON values don't support it. |
| arr_items | vector of key value pairs which will be appended to the root JSON |
|
inline |
Remove all elements from the root JSON document
|
inline |
get the value associated with the key as bool. Note that this function can throw if the underlying value is non-convertible to boolean type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
get the value associated with the key as double. Note that this function can throw if the underlying value is non-convertible to floating point type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
get the value associated with the key as an integer. Note that this function can throw if the underlying value is non-convertible to an integral type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
get the value associated with the key as an integer. Note that this function can throw if the underlying value is non-convertible to an integral type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
get the value associated with the key as std::string. Note that this function can throw if the underlying value is non-convertible to string type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
get the value associated with the key as an unsigned integer. Note that this function can throw if the underlying value is non-convertible to an integral type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
get the value associated with the key as an unsigned integer. Note that this function can throw if the underlying value is non-convertible to an integral type
| name | key to look up in the object |
| def_val | in case key is not found, specify a default value |
|
inline |
() operator overload.
|
inline |
() operator overload for const objects
Copy assignment operator.
| rhs | object to copy document from |
Move assignment operator.
| rhs | json object to move from |
|
inline |
Remove an element from the root JSON object based on a key, if found
| key | key of the entry to drop |
|
inline |
Serialise the JSON object to string for transport or redirect to streams
| pretty_print | Set to true if you wish to pretty print JSON with indentation. Defaulted to false |
|
inlinenoexcept |
Parse a JSON string as JSON object
| json_str | JSON string |
| error | error string if parse results in an error. empty if the conversion is successful |