a class to store JSON values More...
#include <json.hpp>
Classes | |
class | const_iterator |
a const random access iterator for the basic_json class More... | |
struct | internal_iterator |
an iterator value More... | |
class | iteration_proxy |
proxy class for the iterator_wrapper functions More... | |
class | iterator |
a mutable random access iterator for the basic_json class More... | |
class | json_pointer |
JSON Pointer. More... | |
class | json_reverse_iterator |
a template for a reverse iterator class More... | |
union | json_value |
a JSON value More... | |
class | lexer |
lexical analysis More... | |
class | parser |
syntax analysis More... | |
class | primitive_iterator_t |
an iterator for primitive JSON types More... | |
Public Types | |
enum | parse_event_t { object_start, object_end, array_start, array_end, key, value } |
JSON callback events. More... | |
enum | value_t { null, object, array, string, boolean, number_integer, number_unsigned, number_float, discarded } |
the JSON type enumeration More... | |
Static Public Member Functions | |
static allocator_type | get_allocator () |
returns the allocator associated with the container | |
Private Member Functions | |
void | dump (std::ostream &o, const bool pretty_print, const unsigned int indent_step, const unsigned int current_indent=0) const |
internal implementation of the serialization function | |
template<class T , typename std::enable_if< std::is_convertible< typename object_t::key_type, typename T::key_type >::value andstd::is_convertible< basic_json_t, typename T::mapped_type >::value, int >::type = 0> | |
T | get_impl (T *) const |
get an object (explicit) | |
object_t | get_impl (object_t *) const |
get an object (explicit) | |
template<class T , typename std::enable_if< std::is_convertible< basic_json_t, typename T::value_type >::value andnot std::is_same< basic_json_t, typename T::value_type >::value andnot std::is_arithmetic< T >::value andnot std::is_convertible< std::string, T >::value andnot has_mapped_type< T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get an array (explicit) | |
template<class T , typename std::enable_if< std::is_convertible< basic_json_t, T >::value andnot std::is_same< basic_json_t, T >::value, int >::type = 0> | |
std::vector< T > | get_impl (std::vector< T > *) const |
get an array (explicit) | |
template<class T , typename std::enable_if< std::is_same< basic_json, typename T::value_type >::value andnot has_mapped_type< T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get an array (explicit) | |
array_t | get_impl (array_t *) const |
get an array (explicit) | |
template<typename T , typename std::enable_if< std::is_convertible< string_t, T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get a string (explicit) | |
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get a number (explicit) | |
constexpr boolean_t | get_impl (boolean_t *) const |
get a boolean (explicit) | |
object_t * | get_impl_ptr (object_t *) noexcept |
get a pointer to the value (object) | |
constexpr const object_t * | get_impl_ptr (const object_t *) const noexcept |
get a pointer to the value (object) | |
array_t * | get_impl_ptr (array_t *) noexcept |
get a pointer to the value (array) | |
constexpr const array_t * | get_impl_ptr (const array_t *) const noexcept |
get a pointer to the value (array) | |
string_t * | get_impl_ptr (string_t *) noexcept |
get a pointer to the value (string) | |
constexpr const string_t * | get_impl_ptr (const string_t *) const noexcept |
get a pointer to the value (string) | |
boolean_t * | get_impl_ptr (boolean_t *) noexcept |
get a pointer to the value (boolean) | |
constexpr const boolean_t * | get_impl_ptr (const boolean_t *) const noexcept |
get a pointer to the value (boolean) | |
number_integer_t * | get_impl_ptr (number_integer_t *) noexcept |
get a pointer to the value (integer number) | |
constexpr const number_integer_t * | get_impl_ptr (const number_integer_t *) const noexcept |
get a pointer to the value (integer number) | |
number_unsigned_t * | get_impl_ptr (number_unsigned_t *) noexcept |
get a pointer to the value (unsigned number) | |
constexpr const number_unsigned_t * | get_impl_ptr (const number_unsigned_t *) const noexcept |
get a pointer to the value (unsigned number) | |
number_float_t * | get_impl_ptr (number_float_t *) noexcept |
get a pointer to the value (floating-point number) | |
constexpr const number_float_t * | get_impl_ptr (const number_float_t *) const noexcept |
get a pointer to the value (floating-point number) | |
string_t | type_name () const noexcept |
return the type as string | |
Static Private Member Functions | |
template<typename T , typename... Args> | |
static T * | create (Args &&...args) |
helper for exception-safe object creation | |
static string_t | escape_string (const string_t &s) |
escape a string | |
static std::size_t | extra_space (const string_t &s) noexcept |
calculates the extra space to escape a JSON string | |
template<typename ReferenceType , typename ThisType > | |
static ReferenceType | get_ref_impl (ThisType &obj) |
helper function to implement get_ref() | |
Private Attributes | |
value_t | m_type = value_t::null |
the type of the current element | |
json_value | m_value = {} |
the value of the current element | |
constructors and destructors | |
static basic_json | array (std::initializer_list< basic_json > init=std::initializer_list< basic_json >()) |
explicitly create an array from an initializer list | |
static basic_json | object (std::initializer_list< basic_json > init=std::initializer_list< basic_json >()) |
explicitly create an object from an initializer list | |
basic_json (const value_t value_type) | |
create an empty value with a given type | |
basic_json () | |
create a null object (implicitly) | |
basic_json (std::nullptr_t) noexcept | |
create a null object (explicitly) | |
basic_json (const object_t &val) | |
create an object (explicit) | |
template<class CompatibleObjectType , typename std::enable_if< std::is_constructible< typename object_t::key_type, typename CompatibleObjectType::key_type >::value andstd::is_constructible< basic_json, typename CompatibleObjectType::mapped_type >::value, int >::type = 0> | |
basic_json (const CompatibleObjectType &val) | |
create an object (implicit) | |
basic_json (const array_t &val) | |
create an array (explicit) | |
template<class CompatibleArrayType , typename std::enable_if< not std::is_same< CompatibleArrayType, typename basic_json_t::iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::const_iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::reverse_iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::const_reverse_iterator >::value andnot std::is_same< CompatibleArrayType, typename array_t::iterator >::value andnot std::is_same< CompatibleArrayType, typename array_t::const_iterator >::value andstd::is_constructible< basic_json, typename CompatibleArrayType::value_type >::value, int >::type = 0> | |
basic_json (const CompatibleArrayType &val) | |
create an array (implicit) | |
basic_json (const string_t &val) | |
create a string (explicit) | |
basic_json (const typename string_t::value_type *val) | |
create a string (explicit) | |
template<class CompatibleStringType , typename std::enable_if< std::is_constructible< string_t, CompatibleStringType >::value, int >::type = 0> | |
basic_json (const CompatibleStringType &val) | |
create a string (implicit) | |
basic_json (boolean_t val) noexcept | |
create a boolean (explicit) | |
template<typename T , typename std::enable_if< not(std::is_same< T, int >::value) and std::is_same< T, number_integer_t >::value, int >::type = 0> | |
basic_json (const number_integer_t val) noexcept | |
create an integer number (explicit) | |
basic_json (const int val) noexcept | |
create an integer number from an enum type (explicit) | |
template<typename CompatibleNumberIntegerType , typename std::enable_if< std::is_constructible< number_integer_t, CompatibleNumberIntegerType >::value andstd::numeric_limits< CompatibleNumberIntegerType >::is_integer andstd::numeric_limits< CompatibleNumberIntegerType >::is_signed, CompatibleNumberIntegerType >::type = 0> | |
basic_json (const CompatibleNumberIntegerType val) noexcept | |
create an integer number (implicit) | |
template<typename T , typename std::enable_if< not(std::is_same< T, int >::value) and std::is_same< T, number_unsigned_t >::value, int >::type = 0> | |
basic_json (const number_unsigned_t val) noexcept | |
create an unsigned integer number (explicit) | |
template<typename CompatibleNumberUnsignedType , typename std::enable_if< std::is_constructible< number_unsigned_t, CompatibleNumberUnsignedType >::value andstd::numeric_limits< CompatibleNumberUnsignedType >::is_integer andnot std::numeric_limits< CompatibleNumberUnsignedType >::is_signed, CompatibleNumberUnsignedType >::type = 0> | |
basic_json (const CompatibleNumberUnsignedType val) noexcept | |
create an unsigned number (implicit) | |
basic_json (const number_float_t val) noexcept | |
create a floating-point number (explicit) | |
template<typename CompatibleNumberFloatType , typename = typename std::enable_if< std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and std::is_floating_point<CompatibleNumberFloatType>::value>::type> | |
basic_json (const CompatibleNumberFloatType val) noexcept | |
create an floating-point number (implicit) | |
basic_json (std::initializer_list< basic_json > init, bool type_deduction=true, value_t manual_type=value_t::array) | |
create a container (array or object) from an initializer list | |
basic_json (size_type cnt, const basic_json &val) | |
construct an array with count copies of given value | |
template<class InputIT , typename std::enable_if< std::is_same< InputIT, typename basic_json_t::iterator >::value orstd::is_same< InputIT, typename basic_json_t::const_iterator >::value, int >::type = 0> | |
basic_json (InputIT first, InputIT last) | |
construct a JSON container given an iterator range | |
basic_json (std::istream &i, parser_callback_t cb=nullptr) | |
construct a JSON value given an input stream | |
basic_json (const basic_json &other) | |
copy constructor | |
basic_json (basic_json &&other) noexcept | |
move constructor | |
reference & | operator= (basic_json other) noexcept(std |
copy assignment | |
~basic_json () | |
destructor | |
object inspection | |
string_t | dump (const int indent=-1) const |
serialization | |
constexpr value_t | type () const noexcept |
return the type of the JSON value (explicit) | |
constexpr bool | is_primitive () const noexcept |
return whether type is primitive | |
constexpr bool | is_structured () const noexcept |
return whether type is structured | |
constexpr bool | is_null () const noexcept |
return whether value is null | |
constexpr bool | is_boolean () const noexcept |
return whether value is a boolean | |
constexpr bool | is_number () const noexcept |
return whether value is a number | |
constexpr bool | is_number_integer () const noexcept |
return whether value is an integer number | |
constexpr bool | is_number_unsigned () const noexcept |
return whether value is an unsigned integer number | |
constexpr bool | is_number_float () const noexcept |
return whether value is a floating-point number | |
constexpr bool | is_object () const noexcept |
return whether value is an object | |
constexpr bool | is_array () const noexcept |
return whether value is an array | |
constexpr bool | is_string () const noexcept |
return whether value is a string | |
constexpr bool | is_discarded () const noexcept |
return whether value is discarded | |
constexpr | operator value_t () const noexcept |
return the type of the JSON value (implicit) | |
value access | |
template<typename ValueType , typename std::enable_if< not std::is_pointer< ValueType >::value, int >::type = 0> | |
ValueType | get () const |
get a value (explicit) | |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0> | |
PointerType | get () noexcept |
get a pointer value (explicit) | |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0> | |
constexpr const PointerType | get () const noexcept |
get a pointer value (explicit) | |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0> | |
PointerType | get_ptr () noexcept |
get a pointer value (implicit) | |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::valueand std::is_const< typename std::remove_pointer< PointerType >::type >::value, int >::type = 0> | |
constexpr const PointerType | get_ptr () const noexcept |
get a pointer value (implicit) | |
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value, int >::type = 0> | |
ReferenceType | get_ref () |
get a reference value (implicit) | |
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::valueand std::is_const< typename std::remove_reference< ReferenceType >::type >::value, int >::type = 0> | |
ReferenceType | get_ref () const |
get a reference value (implicit) | |
template<typename ValueType , typename std::enable_if< not std::is_pointer< ValueType >::valueand not std::is_same< ValueType, typename string_t::value_type >::valueand not std::is_same< ValueType, std::initializer_list< typename string_t::value_type >>::value, int >::type = 0> | |
operator ValueType () const | |
get a value (implicit) | |
element access | |
reference | at (size_type idx) |
access specified array element with bounds checking | |
const_reference | at (size_type idx) const |
access specified array element with bounds checking | |
reference | at (const typename object_t::key_type &key) |
access specified object element with bounds checking | |
const_reference | at (const typename object_t::key_type &key) const |
access specified object element with bounds checking | |
reference | operator[] (size_type idx) |
access specified array element | |
const_reference | operator[] (size_type idx) const |
access specified array element | |
reference | operator[] (const typename object_t::key_type &key) |
access specified object element | |
const_reference | operator[] (const typename object_t::key_type &key) const |
read-only access specified object element | |
template<typename T , std::size_t n> | |
reference | operator[] (T *(&key)[n]) |
access specified object element | |
template<typename T , std::size_t n> | |
const_reference | operator[] (T *(&key)[n]) const |
read-only access specified object element | |
template<typename T > | |
reference | operator[] (T *key) |
access specified object element | |
template<typename T > | |
const_reference | operator[] (T *key) const |
read-only access specified object element | |
template<class ValueType , typename std::enable_if< std::is_convertible< basic_json_t, ValueType >::value, int >::type = 0> | |
ValueType | value (const typename object_t::key_type &key, ValueType default_value) const |
access specified object element with default value | |
string_t | value (const typename object_t::key_type &key, const char *default_value) const |
overload for a default value of type const char* | |
reference | front () |
access the first element | |
const_reference | front () const |
reference | back () |
access the last element | |
const_reference | back () const |
template<class InteratorType , typename std::enable_if< std::is_same< InteratorType, typename basic_json_t::iterator >::value orstd::is_same< InteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0> | |
InteratorType | erase (InteratorType pos) |
remove element given an iterator | |
template<class InteratorType , typename std::enable_if< std::is_same< InteratorType, typename basic_json_t::iterator >::value orstd::is_same< InteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0> | |
InteratorType | erase (InteratorType first, InteratorType last) |
remove elements given an iterator range | |
size_type | erase (const typename object_t::key_type &key) |
remove element from a JSON object given a key | |
void | erase (const size_type idx) |
remove element from a JSON array given an index | |
lookup | |
iterator | find (typename object_t::key_type key) |
find an element in a JSON object | |
const_iterator | find (typename object_t::key_type key) const |
find an element in a JSON object | |
size_type | count (typename object_t::key_type key) const |
returns the number of occurrences of a key in a JSON object | |
iterators | |
static iteration_proxy< iterator > | iterator_wrapper (reference cont) |
wrapper to access iterator member functions in range-based for | |
static iteration_proxy < const_iterator > | iterator_wrapper (const_reference cont) |
iterator | begin () noexcept |
returns an iterator to the first element | |
const_iterator | begin () const noexcept |
const_iterator | cbegin () const noexcept |
returns a const iterator to the first element | |
iterator | end () noexcept |
returns an iterator to one past the last element | |
const_iterator | end () const noexcept |
const_iterator | cend () const noexcept |
returns a const iterator to one past the last element | |
reverse_iterator | rbegin () noexcept |
returns an iterator to the reverse-beginning | |
const_reverse_iterator | rbegin () const noexcept |
reverse_iterator | rend () noexcept |
returns an iterator to the reverse-end | |
const_reverse_iterator | rend () const noexcept |
const_reverse_iterator | crbegin () const noexcept |
returns a const reverse iterator to the last element | |
const_reverse_iterator | crend () const noexcept |
returns a const reverse iterator to one before the first | |
capacity | |
bool | empty () const noexcept |
checks whether the container is empty | |
size_type | size () const noexcept |
returns the number of elements | |
size_type | max_size () const noexcept |
returns the maximum possible number of elements | |
modifiers | |
void | clear () noexcept |
clears the contents | |
void | push_back (basic_json &&val) |
add an object to an array | |
reference | operator+= (basic_json &&val) |
add an object to an array | |
void | push_back (const basic_json &val) |
add an object to an array | |
reference | operator+= (const basic_json &val) |
add an object to an array | |
void | push_back (const typename object_t::value_type &val) |
add an object to an object | |
reference | operator+= (const typename object_t::value_type &val) |
add an object to an object | |
void | push_back (std::initializer_list< basic_json > init) |
add an object to an object | |
reference | operator+= (std::initializer_list< basic_json > init) |
add an object to an object | |
iterator | insert (const_iterator pos, const basic_json &val) |
inserts element | |
iterator | insert (const_iterator pos, basic_json &&val) |
inserts element | |
iterator | insert (const_iterator pos, size_type cnt, const basic_json &val) |
inserts elements | |
iterator | insert (const_iterator pos, const_iterator first, const_iterator last) |
inserts elements | |
iterator | insert (const_iterator pos, std::initializer_list< basic_json > ilist) |
inserts elements | |
void | swap (reference other) noexcept(std |
exchanges the values | |
void | swap (array_t &other) |
exchanges the values | |
void | swap (object_t &other) |
exchanges the values | |
void | swap (string_t &other) |
exchanges the values | |
lexicographical comparison operators | |
bool | operator< (const value_t lhs, const value_t rhs) noexcept |
comparison operator for JSON types | |
bool | operator== (const_reference lhs, const_reference rhs) noexcept |
comparison: equal | |
bool | operator== (const_reference v, std::nullptr_t) noexcept |
comparison: equal | |
bool | operator== (std::nullptr_t, const_reference v) noexcept |
comparison: equal | |
bool | operator!= (const_reference lhs, const_reference rhs) noexcept |
comparison: not equal | |
bool | operator!= (const_reference v, std::nullptr_t) noexcept |
comparison: not equal | |
bool | operator!= (std::nullptr_t, const_reference v) noexcept |
comparison: not equal | |
bool | operator< (const_reference lhs, const_reference rhs) noexcept |
comparison: less than | |
bool | operator<= (const_reference lhs, const_reference rhs) noexcept |
comparison: less than or equal | |
bool | operator> (const_reference lhs, const_reference rhs) noexcept |
comparison: greater than | |
bool | operator>= (const_reference lhs, const_reference rhs) noexcept |
comparison: greater than or equal | |
serialization | |
std::ostream & | operator<< (std::ostream &o, const basic_json &j) |
serialize to stream | |
std::ostream & | operator>> (const basic_json &j, std::ostream &o) |
serialize to stream | |
deserialization | |
static basic_json | parse (const string_t &s, parser_callback_t cb=nullptr) |
deserialize from string | |
static basic_json | parse (std::istream &i, parser_callback_t cb=nullptr) |
deserialize from stream | |
static basic_json | parse (std::istream &&i, parser_callback_t cb=nullptr) |
std::istream & | operator<< (basic_json &j, std::istream &i) |
deserialize from stream | |
std::istream & | operator>> (std::istream &i, basic_json &j) |
deserialize from stream | |
JSON Pointer functions | |
reference | operator[] (const json_pointer &ptr) |
access specified element via JSON Pointer | |
const_reference | operator[] (const json_pointer &ptr) const |
access specified element via JSON Pointer | |
reference | at (const json_pointer &ptr) |
access specified element via JSON Pointer | |
const_reference | at (const json_pointer &ptr) const |
access specified element via JSON Pointer | |
basic_json | flatten () const |
return flattened JSON value | |
basic_json | unflatten () const |
unflatten a previously flattened JSON value | |
JSON Patch functions | |
static basic_json | diff (const basic_json &source, const basic_json &target, std::string path="") |
creates a diff as a JSON patch | |
basic_json | patch (const basic_json &json_patch) const |
applies a JSON patch |
a class to store JSON values
ObjectType | type for JSON objects (`std::map` by default; will be used in object_t) |
ArrayType | type for JSON arrays (`std::vector` by default; will be used in array_t) |
StringType | type for JSON strings and object keys (`std::string` by default; will be used in string_t) |
BooleanType | type for JSON booleans (`bool` by default; will be used in boolean_t) |
NumberIntegerType | type for JSON integer numbers (`int64_t` by default; will be used in number_integer_t) |
NumberUnsignedType | type for JSON unsigned integer numbers (`uint64_t` by default; will be used in number_unsigned_t) |
NumberFloatType | type for JSON floating-point numbers (`double` by default; will be used in number_float_t) |
AllocatorType | type of the allocator to use (`std::allocator` by default) |
The class satisfies the following concept requirements:
enum nlohmann::basic_json::parse_event_t |
JSON callback events.
This enumeration lists the parser events that can trigger calling a callback function of type parser_callback_t during parsing.
enum nlohmann::basic_json::value_t |
the JSON type enumeration
This enumeration collects the different JSON types. It is internally used to distinguish the stored values, and the functions is_null(), is_object(), is_array(), is_string(), is_boolean(), is_number(), and is_discarded() rely on it.
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const value_t | value_type | ) | [inline] |
create an empty value with a given type
Create an empty JSON value with a given type. The value will be default initialized with an empty value which depends on the type:
Value type | initial value ----------- | ------------- null | `null` boolean | `false` string | `""` number | `0` object | `{}` array | `[]`
[in] | value_type | the type of the value to create |
Constant.
std::bad_alloc | if allocation for object, array, or string value fails |
{The following code shows the constructor for different value_t values,basic_json__value_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | ) |
create a null object (implicitly)
Create a `null` JSON value. This is the implicit version of the `null` value constructor as it takes no parameters.
Constant.
No-throw guarantee: this constructor never throws exceptions.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows the constructor for a `null` JSON value.,basic_json}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | std::nullptr_t | ) | [inline] |
create a null object (explicitly)
Create a `null` JSON value. This is the explicitly version of the `null` value constructor as it takes a null pointer as parameter. It allows to create `null` values by explicitly assigning a `nullptr` to a JSON value. The passed null pointer itself is not read -- it is only used to choose the right constructor.
Constant.
No-throw guarantee: this constructor never throws exceptions.
{The following code shows the constructor with null pointer parameter.,basic_json__nullptr_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const object_t & | val | ) | [inline] |
create an object (explicit)
Create an object JSON value with a given content.
[in] | val | a value for the object |
Linear in the size of the passed val.
std::bad_alloc | if allocation for object value fails |
{The following code shows the constructor with an object_t parameter.,basic_json__object_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const CompatibleObjectType & | val | ) | [inline] |
create an object (implicit)
Create an object JSON value with a given content. This constructor allows any type CompatibleObjectType that can be used to construct values of type object_t.
CompatibleObjectType | An object type whose `key_type` and `value_type` is compatible to object_t. Examples include `std::map`, `std::unordered_map`, `std::multimap`, and `std::unordered_multimap` with a `key_type` of `std::string`, and a `value_type` from which a basic_json value can be constructed. |
[in] | val | a value for the object |
Linear in the size of the passed val.
std::bad_alloc | if allocation for object value fails |
{The following code shows the constructor with several compatible object type parameters.,basic_json__CompatibleObjectType}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const array_t & | val | ) | [inline] |
create an array (explicit)
Create an array JSON value with a given content.
[in] | val | a value for the array |
Linear in the size of the passed val.
std::bad_alloc | if allocation for array value fails |
{The following code shows the constructor with an array_t parameter.,basic_json__array_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const CompatibleArrayType & | val | ) | [inline] |
create an array (implicit)
Create an array JSON value with a given content. This constructor allows any type CompatibleArrayType that can be used to construct values of type array_t.
CompatibleArrayType | An object type whose `value_type` is compatible to array_t. Examples include `std::vector`, `std::deque`, `std::list`, `std::forward_list`, `std::array`, `stdset`, `std::unordered_set`, `std::multiset`, and `unordered_multiset` with a `value_type` from which a basic_json value can be constructed. |
[in] | val | a value for the array |
Linear in the size of the passed val.
std::bad_alloc | if allocation for array value fails |
{The following code shows the constructor with several compatible array type parameters.,basic_json__CompatibleArrayType}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const string_t & | val | ) | [inline] |
create a string (explicit)
Create an string JSON value with a given content.
[in] | val | a value for the string |
Linear in the size of the passed val.
std::bad_alloc | if allocation for string value fails |
{The following code shows the constructor with an string_t parameter.,basic_json__string_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const typename string_t::value_type * | val | ) | [inline] |
create a string (explicit)
Create a string JSON value with a given content.
[in] | val | a literal value for the string |
Linear in the size of the passed val.
std::bad_alloc | if allocation for string value fails |
{The following code shows the constructor with string literal parameter.,basic_json__string_t_value_type}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const CompatibleStringType & | val | ) | [inline] |
create a string (implicit)
Create a string JSON value with a given content.
[in] | val | a value for the string |
CompatibleStringType | an string type which is compatible to string_t, for instance `std::string`. |
Linear in the size of the passed val.
std::bad_alloc | if allocation for string value fails |
{The following code shows the construction of a string value from a compatible type.,basic_json__CompatibleStringType}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | boolean_t | val | ) | [inline] |
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const number_integer_t | val | ) | [inline] |
create an integer number (explicit)
Create an integer number JSON value with a given content.
T | A helper type to remove this function via SFINAE in case number_integer_t is the same as `int`. In this case, this constructor would have the same signature as basic_json(const int value). Note the helper type T is not visible in this constructor's interface. |
[in] | val | an integer to create a JSON number from |
Constant.
{The example below shows the construction of an integer number value.,basic_json__number_integer_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const int | val | ) | [inline] |
create an integer number from an enum type (explicit)
Create an integer number JSON value with a given content.
[in] | val | an integer to create a JSON number from |
Constant.
{The example below shows the construction of an integer number value from an anonymous enum.,basic_json__const_int}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const CompatibleNumberIntegerType | val | ) | [inline] |
create an integer number (implicit)
Create an integer number JSON value with a given content. This constructor allows any type CompatibleNumberIntegerType that can be used to construct values of type number_integer_t.
CompatibleNumberIntegerType | An integer type which is compatible to number_integer_t. Examples include the types `int`, `int32_t`, `long`, and `short`. |
[in] | val | an integer to create a JSON number from |
Constant.
{The example below shows the construction of several integer number values from compatible types.,basic_json__CompatibleIntegerNumberType}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const number_unsigned_t | val | ) | [inline] |
create an unsigned integer number (explicit)
Create an unsigned integer number JSON value with a given content.
T | helper type to compare number_unsigned_t and unsigned int (not visible in) the interface. |
[in] | val | an integer to create a JSON number from |
Constant.
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const CompatibleNumberUnsignedType | val | ) | [inline] |
create an unsigned number (implicit)
Create an unsigned number JSON value with a given content. This constructor allows any type CompatibleNumberUnsignedType that can be used to construct values of type number_unsigned_t.
CompatibleNumberUnsignedType | An integer type which is compatible to number_unsigned_t. Examples may include the types `unsigned int`, `uint32_t`, or `unsigned short`. |
[in] | val | an unsigned integer to create a JSON number from |
Constant.
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const number_float_t | val | ) | [inline] |
create a floating-point number (explicit)
Create a floating-point number JSON value with a given content.
[in] | val | a floating-point value to create a JSON number from |
Constant.
{The following example creates several floating-point values.,basic_json__number_float_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const CompatibleNumberFloatType | val | ) | [inline] |
create an floating-point number (implicit)
Create an floating-point number JSON value with a given content. This constructor allows any type CompatibleNumberFloatType that can be used to construct values of type number_float_t.
CompatibleNumberFloatType | A floating-point type which is compatible to number_float_t. Examples may include the types `float` or `double`. |
[in] | val | a floating-point to create a JSON number from |
Constant.
{The example below shows the construction of several floating-point number values from compatible types.,basic_json__CompatibleNumberFloatType}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > > | init, |
bool | type_deduction = true , |
||
value_t | manual_type = value_t::array |
||
) | [inline] |
create a container (array or object) from an initializer list
Creates a JSON value of type array or object from the passed initializer list init. In case type_deduction is `true` (default), the type of the JSON value to be created is deducted from the initializer list init according to the following rules:
1. If the list is empty, an empty JSON object value `{}` is created. 2. If the list consists of pairs whose first element is a string, a JSON object value is created where the first elements of the pairs are treated as keys and the second elements are as values. 3. In all other cases, an array is created.
The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:
1. The empty initializer list is written as `{}` which is exactly an empty JSON object. 2. C++ has now way of describing mapped types other than to list a list of pairs. As JSON requires that keys must be of type string, rule 2 is the weakest constraint one can pose on initializer lists to interpret them as an object. 3. In all other cases, the initializer list could not be interpreted as JSON object type, so interpreting it as JSON array type is safe.
With the rules described above, the following JSON values cannot be expressed by an initializer list:
[in] | init | initializer list with JSON values |
[in] | type_deduction | internal parameter; when set to `true`, the type of the JSON value is deducted from the initializer list init; when set to `false`, the type provided via manual_type is forced. This mode is used by the functions array(std::initializer_list<basic_json>) and object(std::initializer_list<basic_json>). |
[in] | manual_type | internal parameter; when type_deduction is set to `false`, the created JSON value will use the provided type (only value_t::array and value_t::object are valid); when type_deduction is set to `true`, this parameter has no effect |
std::domain_error | if type_deduction is `false`, manual_type is `value_t::object`, but init contains an element which is not a pair whose first element is a string; example: `"cannot create object from initializer list"` |
Linear in the size of the initializer list init.
{The example below shows how JSON values are created from initializer lists.,basic_json__list_init_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | size_type | cnt, |
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | val | ||
) | [inline] |
construct an array with count copies of given value
Constructs a JSON array value by creating cnt copies of a passed value. In case cnt is `0`, an empty array is created. As postcondition, `stddistance(begin(),end()) == cnt` holds.
[in] | cnt | the number of JSON copies of val to create |
[in] | val | the JSON value to copy |
Linear in cnt.
{The following code shows examples for the basic_json(size_type\, const basic_json&) constructor.,basic_json__size_type_basic_json}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | InputIT | first, |
InputIT | last | ||
) | [inline] |
construct a JSON container given an iterator range
Constructs the JSON value with the contents of the range `[first, last)`. The semantics depends on the different types a JSON value can have:
InputIT | an input iterator type (iterator or const_iterator) |
[in] | first | begin of the range to copy from (included) |
[in] | last | end of the range to copy from (excluded) |
std::domain_error | if iterators are not compatible; that is, do not belong to the same JSON value; example: `"iterators are not compatible"` |
std::out_of_range | if iterators are for a primitive type (number, boolean, or string) where an out of range error can be detected easily; example: `"iterators out of range"` |
std::bad_alloc | if allocation for object, array, or string fails |
std::domain_error | if called with a null value; example: `"cannot use construct with iterators from null"` |
Linear in distance between first and last.
{The example below shows several ways to create JSON values by specifying a subrange with iterators.,basic_json__InputIt_InputIt}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | std::istream & | i, |
parser_callback_t | cb = nullptr |
||
) | [inline, explicit] |
construct a JSON value given an input stream
[in,out] | i | stream to read a serialized JSON value from |
[in] | cb | a parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional) |
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
{The example below demonstrates constructing a JSON value from a `std::stringstream` with and without callback function.,basic_json__istream}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | other | ) | [inline] |
copy constructor
Creates a copy of a given JSON value.
[in] | other | the JSON value to copy |
Linear in the size of other.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
std::bad_alloc | if allocation for object, array, or string fails. |
{The following code shows an example for the copy constructor.,basic_json__basic_json}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json | ( | basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > && | other | ) | [inline] |
move constructor
Move constructor. Constructs a JSON value with the contents of the given value other using move semantics. It "steals" the resources from other and leaves it as JSON null value.
[in,out] | other | value to move to this object |
Constant.
{The code below shows the move constructor explicitly called via std::move.,basic_json__moveconstructor}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::~basic_json | ( | ) | [inline] |
destructor
Destroys the JSON value and frees all allocated memory.
Linear.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::array | ( | std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > > | init = std::initializer_list<basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >>() | ) | [inline, static] |
explicitly create an array from an initializer list
Creates a JSON array value from a given initializer list. That is, given a list of values `a, b, c`, creates the JSON value `[a, b, c]`. If the initializer list is empty, the empty array `[]` is created.
[in] | init | initializer list with JSON values to create an array from (optional) |
Linear in the size of init.
{The following code shows an example for the `array` function.,array}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at | ( | size_type | idx | ) | [inline] |
access specified array element with bounds checking
Returns a reference to the element at specified location idx, with bounds checking.
[in] | idx | index of the element to access |
std::domain_error | if the JSON value is not an array; example: `"cannot use at() with string"` |
std::out_of_range | if the index idx is out of range of the array; that is, `idx >= size()`; example: `"array index 7 is out of range"` |
Constant.
{The example below shows how array elements can be read and written using `at()`.,at__size_type}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at | ( | size_type | idx | ) | const [inline] |
access specified array element with bounds checking
Returns a const reference to the element at specified location idx, with bounds checking.
[in] | idx | index of the element to access |
std::domain_error | if the JSON value is not an array; example: `"cannot use at() with string"` |
std::out_of_range | if the index idx is out of range of the array; that is, `idx >= size()`; example: `"array index 7 is out of range"` |
Constant.
{The example below shows how array elements can be read using `at()`.,at__size_type_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at | ( | const typename object_t::key_type & | key | ) | [inline] |
access specified object element with bounds checking
Returns a reference to the element at with specified key key, with bounds checking.
[in] | key | key of the element to access |
std::domain_error | if the JSON value is not an object; example: `"cannot use at() with boolean"` |
std::out_of_range | if the key key is is not stored in the object; that is, `find(key) == end()`; example: `"key "the fast" not found"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read and written using `at()`.,at__object_t_key_type}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at | ( | const typename object_t::key_type & | key | ) | const [inline] |
access specified object element with bounds checking
Returns a const reference to the element at with specified key key, with bounds checking.
[in] | key | key of the element to access |
std::domain_error | if the JSON value is not an object; example: `"cannot use at() with boolean"` |
std::out_of_range | if the key key is is not stored in the object; that is, `find(key) == end()`; example: `"key "the fast" not found"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read using `at()`.,at__object_t_key_type_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at | ( | const json_pointer & | ptr | ) | [inline] |
access specified element via JSON Pointer
Returns a reference to the element at with specified JSON pointer ptr, with bounds checking.
[in] | ptr | JSON pointer to the desired element |
Constant.
std::out_of_range | if the JSON pointer can not be resolved |
std::domain_error | if an array index begins with '0' |
std::invalid_argument | if an array index was not a number |
{The behavior is shown in the example.,at_json_pointer}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at | ( | const json_pointer & | ptr | ) | const [inline] |
access specified element via JSON Pointer
Returns a const reference to the element at with specified JSON pointer ptr, with bounds checking.
[in] | ptr | JSON pointer to the desired element |
Constant.
std::out_of_range | if the JSON pointer can not be resolved |
std::domain_error | if an array index begins with '0' |
std::invalid_argument | if an array index was not a number |
{The behavior is shown in the example.,at_json_pointer_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::back | ( | ) | [inline] |
access the last element
Returns a reference to the last element in the container. For a JSON container `c`, the expression `c.back()` is equivalent to
{.cpp} auto tmp = c.end(); --tmp; return *tmp;
Constant.
std::out_of_range | when called on `null` value. |
{The following code shows an example for `back()`.,back}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::back | ( | ) | const [inline] |
access the last element
Returns a reference to the last element in the container. For a JSON container `c`, the expression `c.back()` is equivalent to
{.cpp} auto tmp = c.end(); --tmp; return *tmp;
Constant.
std::out_of_range | when called on `null` value. |
{The following code shows an example for `back()`.,back}
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::begin | ( | ) | [inline] |
returns an iterator to the first element
Returns an iterator to the first element.
Constant.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows an example for `begin()`.,begin}
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::begin | ( | ) | const [inline] |
returns a const iterator to the first element
Returns a const iterator to the first element.
Constant.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows an example for `cbegin()`.,cbegin}
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::cbegin | ( | ) | const [inline] |
returns a const iterator to the first element
Returns a const iterator to the first element.
Constant.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows an example for `cbegin()`.,cbegin}
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::cend | ( | ) | const [inline] |
returns a const iterator to one past the last element
Returns a const iterator to one past the last element.
Constant.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows an example for `cend()`.,cend}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::clear | ( | ) | [inline] |
clears the contents
Clears the content of a JSON value and resets it to the default value as if basic_json(value_t) would have been called:
Value type | initial value ----------- | ------------- null | `null` boolean | `false` string | `""` number | `0` object | `{}` array | `[]`
Linear in the size of the JSON value.
{The example below shows the effect of `clear()` to different JSON types.,clear}
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::count | ( | typename object_t::key_type | key | ) | const [inline] |
returns the number of occurrences of a key in a JSON object
Returns the number of elements with key key. If ObjectType is the default `std::map` type, the return value will always be `0` (key was not found) or `1` (key was found).
[in] | key | key value of the element to count |
Logarithmic in the size of the JSON object.
{The example shows how `count()` is used.,count}
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::crbegin | ( | ) | const [inline] |
returns a const reverse iterator to the last element
Returns a const iterator to the reverse-beginning; that is, the last element.
Constant.
This function helps `basic_json` satisfying the [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirements:
{The following code shows an example for `crbegin()`.,crbegin}
static T* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::create | ( | Args &&... | args | ) | [inline, static, private] |
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::crend | ( | ) | const [inline] |
returns a const reverse iterator to one before the first
Returns a const reverse iterator to the reverse-end; that is, one before the first element.
Constant.
This function helps `basic_json` satisfying the [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirements:
{The following code shows an example for `crend()`.,crend}
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::diff | ( | const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | source, |
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | target, | ||
std::string | path = "" |
||
) | [inline, static] |
creates a diff as a JSON patch
Creates a [JSON Patch](http://jsonpatch.com) so that value source can be changed into the value target by calling patch function.
{.cpp} source.patch(diff(source, target)) == target;
[in] | source | JSON value to copare from |
[in] | target | JSON value to copare against |
[in] | path | helper value to create JSON pointers |
Linear in the lengths of source and target.
{The following code shows how a JSON patch is created as a diff for two JSON values.,diff}
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::dump | ( | const int | indent = -1 | ) | const [inline] |
serialization
Serialization function for JSON values. The function tries to mimic Python's json.dumps()
function, and currently supports its indent
parameter.
[in] | indent | if indent is nonnegative, then array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. -1 (the default) selects the most compact representation |
Linear.
{The following example shows the effect of different indent parameters to the result of the serialization.,dump}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::dump | ( | std::ostream & | o, |
const bool | pretty_print, | ||
const unsigned int | indent_step, | ||
const unsigned int | current_indent = 0 |
||
) | const [inline, private] |
internal implementation of the serialization function
This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively. Note that
[out] | o | stream to write to |
[in] | pretty_print | whether the output shall be pretty-printed |
[in] | indent_step | the indent level |
[in] | current_indent | the current indent level (only used internally) |
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::empty | ( | ) | const [inline] |
checks whether the container is empty
Checks if a JSON value has no elements.
Constant, as long as array_t and object_t satisfy the Container concept; that is, their `empty()` functions have constant complexity.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code uses `empty()` to check if a JSON object contains any elements.,empty}
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::end | ( | ) | [inline] |
returns an iterator to one past the last element
Returns an iterator to one past the last element.
Constant.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows an example for `end()`.,end}
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::end | ( | ) | const [inline] |
returns a const iterator to one past the last element
Returns a const iterator to one past the last element.
Constant.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code shows an example for `cend()`.,cend}
InteratorType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase | ( | InteratorType | pos | ) | [inline] |
remove element given an iterator
Removes the element specified by iterator pos. The iterator pos must be valid and dereferenceable. Thus the `end()` iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.
If called on a primitive type other than `null`, the resulting JSON value will be `null`.
[in] | pos | iterator to the element to remove |
InteratorType | an iterator or const_iterator |
std::domain_error | if called on a `null` value; example: `"cannot use erase() with null"` |
std::domain_error | if called on an iterator which does not belong to the current JSON value; example: `"iterator does not fit current value"` |
std::out_of_range | if called on a primitive type with invalid iterator (i.e., any iterator which is not `begin()`); example: `"iterator out of range"` |
The complexity depends on the type:
{The example shows the result of `erase()` for different JSON types.,erase__IteratorType}
InteratorType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase | ( | InteratorType | first, |
InteratorType | last | ||
) | [inline] |
remove elements given an iterator range
Removes the element specified by the range `[first; last)`. The iterator first does not need to be dereferenceable if `first == last`: erasing an empty range is a no-op.
If called on a primitive type other than `null`, the resulting JSON value will be `null`.
[in] | first | iterator to the beginning of the range to remove |
[in] | last | iterator past the end of the range to remove |
InteratorType | an iterator or const_iterator |
std::domain_error | if called on a `null` value; example: `"cannot use erase() with null"` |
std::domain_error | if called on iterators which does not belong to the current JSON value; example: `"iterators do not fit current value"` |
std::out_of_range | if called on a primitive type with invalid iterators (i.e., if `first != begin()` and `last != end()`); example: `"iterators out of range"` |
The complexity depends on the type:
{The example shows the result of `erase()` for different JSON types.,erase__IteratorType_IteratorType}
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase | ( | const typename object_t::key_type & | key | ) | [inline] |
remove element from a JSON object given a key
Removes elements from a JSON object with the key value key.
[in] | key | value of the elements to remove |
std::domain_error | when called on a type other than JSON object; example: `"cannot use erase() with null"` |
`log(size()) + count(key)`
{The example shows the effect of `erase()`.,erase__key_type}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase | ( | const size_type | idx | ) | [inline] |
remove element from a JSON array given an index
Removes element from a JSON array at the index idx.
[in] | idx | index of the element to remove |
std::domain_error | when called on a type other than JSON array; example: `"cannot use erase() with null"` |
std::out_of_range | when `idx >= size()`; example: `"array index 17 is out of range"` |
Linear in distance between idx and the end of the container.
{The example shows the effect of `erase()`.,erase__size_type}
static string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::escape_string | ( | const string_t & | s | ) | [inline, static, private] |
escape a string
Escape a string by replacing certain special characters by a sequence of an escape character (backslash) and another character and other control characters by a sequence of "\u" followed by a four-digit hex representation.
[in] | s | the string to escape |
Linear in the length of string s.
static std::size_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::extra_space | ( | const string_t & | s | ) | [inline, static, private] |
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::find | ( | typename object_t::key_type | key | ) | [inline] |
find an element in a JSON object
Finds an element in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, end() is returned.
[in] | key | key value of the element to search for |
Logarithmic in the size of the JSON object.
{The example shows how `find()` is used.,find__key_type}
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::find | ( | typename object_t::key_type | key | ) | const [inline] |
find an element in a JSON object
find an element in a JSON object
Finds an element in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, end() is returned.
[in] | key | key value of the element to search for |
Logarithmic in the size of the JSON object.
{The example shows how `find()` is used.,find__key_type}
basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::flatten | ( | ) | const [inline] |
return flattened JSON value
The function creates a JSON object whose keys are JSON pointers (see [RFC 6901](https://tools.ietf.org/html/rfc6901)) and whose values are all primitive. The original JSON value can be restored using the unflatten() function.
Linear in the size the JSON value.
{The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.,flatten}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::front | ( | ) | [inline] |
access the first element
Returns a reference to the first element in the container. For a JSON container `c`, the expression `c.front()` is equivalent to `*c.begin()`.
Constant.
std::out_of_range | when called on `null` value |
{The following code shows an example for `front()`.,front}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::front | ( | ) | const [inline] |
access the first element
Returns a reference to the first element in the container. For a JSON container `c`, the expression `c.front()` is equivalent to `*c.begin()`.
Constant.
std::out_of_range | when called on `null` value |
{The following code shows an example for `front()`.,front}
ValueType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get | ( | ) | const [inline] |
get a value (explicit)
Explicit type conversion between the JSON value and a compatible value.
ValueType | non-pointer type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for JSON arrays |
std::domain_error | in case passed type ValueType is incompatible to JSON; example: `"type must be object, but is null"` |
Linear in the size of the JSON value.
{The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers\, (2) A JSON array can be converted to a standard `std::vector<short>`\, (3) A JSON object can be converted to C++ associative containers such as `std::unordered_map<std::string\, json>`.,get__ValueType_const}
PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get | ( | ) | [inline] |
get a pointer value (explicit)
Explicit pointer access to the internally stored JSON value. No copies are made.
PointerType | pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. |
Constant.
{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a `nullptr` is returned if the value and the requested pointer type does not match.,get__PointerType}
constexpr const PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get | ( | ) | const [inline] |
get a pointer value (explicit)
get a pointer value (explicit)
Explicit pointer access to the internally stored JSON value. No copies are made.
PointerType | pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. |
Constant.
{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a `nullptr` is returned if the value and the requested pointer type does not match.,get__PointerType}
static allocator_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_allocator | ( | ) | [inline, static] |
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | T * | ) | const [inline, private] |
object_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | object_t * | ) | const [inline, private] |
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | T * | ) | const [inline, private] |
std::vector<T> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | std::vector< T > * | ) | const [inline, private] |
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | T * | ) | const [inline, private] |
array_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | array_t * | ) | const [inline, private] |
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | T * | ) | const [inline, private] |
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | T * | ) | const [inline, private] |
constexpr boolean_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl | ( | boolean_t * | ) | const [inline, private] |
object_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | object_t * | ) | [inline, private] |
constexpr const object_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const object_t * | ) | const [inline, private] |
array_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | array_t * | ) | [inline, private] |
constexpr const array_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const array_t * | ) | const [inline, private] |
string_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | string_t * | ) | [inline, private] |
constexpr const string_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const string_t * | ) | const [inline, private] |
boolean_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | boolean_t * | ) | [inline, private] |
constexpr const boolean_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const boolean_t * | ) | const [inline, private] |
number_integer_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | number_integer_t * | ) | [inline, private] |
constexpr const number_integer_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const number_integer_t * | ) | const [inline, private] |
number_unsigned_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | number_unsigned_t * | ) | [inline, private] |
constexpr const number_unsigned_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const number_unsigned_t * | ) | const [inline, private] |
number_float_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | number_float_t * | ) | [inline, private] |
constexpr const number_float_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl_ptr | ( | const number_float_t * | ) | const [inline, private] |
PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ptr | ( | ) | [inline] |
get a pointer value (implicit)
Implicit pointer access to the internally stored JSON value. No copies are made.
PointerType | pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. |
Constant.
{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a `nullptr` is returned if the value and the requested pointer type does not match.,get_ptr}
constexpr const PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ptr | ( | ) | const [inline] |
get a pointer value (implicit)
get a pointer value (implicit)
Implicit pointer access to the internally stored JSON value. No copies are made.
PointerType | pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. |
Constant.
{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a `nullptr` is returned if the value and the requested pointer type does not match.,get_ptr}
ReferenceType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ref | ( | ) | [inline] |
get a reference value (implicit)
Implict reference access to the internally stored JSON value. No copies are made.
ReferenceType | reference type; must be a reference to array_t, object_t, string_t, boolean_t, number_integer_t, or number_float_t. |
std::domain_error | in case passed type ReferenceType is incompatible with the stored JSON value |
Constant.
{The example shows several calls to `get_ref()`.,get_ref}
ReferenceType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ref | ( | ) | const [inline] |
get a reference value (implicit)
get a reference value (implicit)
Implict reference access to the internally stored JSON value. No copies are made.
ReferenceType | reference type; must be a reference to array_t, object_t, string_t, boolean_t, number_integer_t, or number_float_t. |
std::domain_error | in case passed type ReferenceType is incompatible with the stored JSON value |
Constant.
{The example shows several calls to `get_ref()`.,get_ref}
static ReferenceType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ref_impl | ( | ThisType & | obj | ) | [inline, static, private] |
helper function to implement get_ref()
This funcion helps to implement get_ref() without code duplication for const and non-const overloads
ThisType | will be deduced as `basic_json` or `const basic_json` |
std::domain_error | if ReferenceType does not match underlying value type of the current JSON |
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::insert | ( | const_iterator | pos, |
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | val | ||
) | [inline] |
inserts element
Inserts element val before iterator pos.
[in] | pos | iterator before which the content will be inserted; may be the end() iterator |
[in] | val | element to insert |
std::domain_error | if called on JSON values other than arrays; example: `"cannot use insert() with string"` |
std::domain_error | if pos is not an iterator of *this; example: `"iterator does not fit current value"` |
Constant plus linear in the distance between pos and end of the container.
{The example shows how `insert()` is used.,insert}
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::insert | ( | const_iterator | pos, |
basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > && | val | ||
) | [inline] |
inserts element
inserts element
Inserts element val before iterator pos.
[in] | pos | iterator before which the content will be inserted; may be the end() iterator |
[in] | val | element to insert |
std::domain_error | if called on JSON values other than arrays; example: `"cannot use insert() with string"` |
std::domain_error | if pos is not an iterator of *this; example: `"iterator does not fit current value"` |
Constant plus linear in the distance between pos and end of the container.
{The example shows how `insert()` is used.,insert}
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::insert | ( | const_iterator | pos, |
size_type | cnt, | ||
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | val | ||
) | [inline] |
inserts elements
Inserts cnt copies of val before iterator pos.
[in] | pos | iterator before which the content will be inserted; may be the end() iterator |
[in] | cnt | number of copies of val to insert |
[in] | val | element to insert |
std::domain_error | if called on JSON values other than arrays; example: `"cannot use insert() with string"` |
std::domain_error | if pos is not an iterator of *this; example: `"iterator does not fit current value"` |
Linear in cnt plus linear in the distance between pos and end of the container.
{The example shows how `insert()` is used.,insert__count}
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::insert | ( | const_iterator | pos, |
const_iterator | first, | ||
const_iterator | last | ||
) | [inline] |
inserts elements
Inserts elements from range `[first, last)` before iterator pos.
[in] | pos | iterator before which the content will be inserted; may be the end() iterator |
[in] | first | begin of the range of elements to insert |
[in] | last | end of the range of elements to insert |
std::domain_error | if called on JSON values other than arrays; example: `"cannot use insert() with string"` |
std::domain_error | if pos is not an iterator of *this; example: `"iterator does not fit current value"` |
std::domain_error | if first and last do not belong to the same JSON value; example: `"iterators do not fit"` |
std::domain_error | if first or last are iterators into container for which insert is called; example: `"passed iterators may not belong to container"` |
Linear in `std::distance(first, last)` plus linear in the distance between pos and end of the container.
{The example shows how `insert()` is used.,insert__range}
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::insert | ( | const_iterator | pos, |
std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > > | ilist | ||
) | [inline] |
inserts elements
Inserts elements from initializer list ilist before iterator pos.
[in] | pos | iterator before which the content will be inserted; may be the end() iterator |
[in] | ilist | initializer list to insert the values from |
std::domain_error | if called on JSON values other than arrays; example: `"cannot use insert() with string"` |
std::domain_error | if pos is not an iterator of *this; example: `"iterator does not fit current value"` |
Linear in `ilist.size()` plus linear in the distance between pos and end of the container.
{The example shows how `insert()` is used.,insert__ilist}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_array | ( | ) | const [inline] |
return whether value is an array
This function returns true iff the JSON value is an array.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_array()` for all JSON types.,is_array}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_boolean | ( | ) | const [inline] |
return whether value is a boolean
This function returns true iff the JSON value is a boolean.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_boolean()` for all JSON types.,is_boolean}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_discarded | ( | ) | const [inline] |
return whether value is discarded
This function returns true iff the JSON value was discarded during parsing with a callback function (see parser_callback_t).
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_discarded()` for all JSON types.,is_discarded}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_null | ( | ) | const [inline] |
return whether value is null
This function returns true iff the JSON value is null.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_null()` for all JSON types.,is_null}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_number | ( | ) | const [inline] |
return whether value is a number
This function returns true iff the JSON value is a number. This includes both integer and floating-point values.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_number()` for all JSON types.,is_number}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_number_float | ( | ) | const [inline] |
return whether value is a floating-point number
This function returns true iff the JSON value is a floating-point number. This excludes integer and unsigned integer values.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_number_float()` for all JSON types.,is_number_float}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_number_integer | ( | ) | const [inline] |
return whether value is an integer number
This function returns true iff the JSON value is an integer or unsigned integer number. This excludes floating-point values.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_number_integer()` for all JSON types.,is_number_integer}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_number_unsigned | ( | ) | const [inline] |
return whether value is an unsigned integer number
This function returns true iff the JSON value is an unsigned integer number. This excludes floating-point and (signed) integer values.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_number_unsigned()` for all JSON types.,is_number_unsigned}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_object | ( | ) | const [inline] |
return whether value is an object
This function returns true iff the JSON value is an object.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_object()` for all JSON types.,is_object}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_primitive | ( | ) | const [inline] |
return whether type is primitive
This function returns true iff the JSON type is primitive (string, number, boolean, or null).
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_primitive()` for all JSON types.,is_primitive}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_string | ( | ) | const [inline] |
return whether value is a string
This function returns true iff the JSON value is a string.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_string()` for all JSON types.,is_string}
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::is_structured | ( | ) | const [inline] |
return whether type is structured
This function returns true iff the JSON type is structured (array or object).
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `is_structured()` for all JSON types.,is_structured}
static iteration_proxy<iterator> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::iterator_wrapper | ( | reference | cont | ) | [inline, static] |
wrapper to access iterator member functions in range-based for
This function allows to access iterator::key() and iterator::value() during range-based for loops. In these loops, a reference to the JSON values is returned, so there is no access to the underlying iterator.
static iteration_proxy<const_iterator> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::iterator_wrapper | ( | const_reference | cont | ) | [inline, static] |
wrapper to access iterator member functions in range-based for
This function allows to access iterator::key() and iterator::value() during range-based for loops. In these loops, a reference to the JSON values is returned, so there is no access to the underlying iterator.
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::max_size | ( | ) | const [inline] |
returns the maximum possible number of elements
Returns the maximum number of elements a JSON value is able to hold due to system or library implementation limitations, i.e. `stddistance(begin(), end())` for the JSON value.
Constant, as long as array_t and object_t satisfy the Container concept; that is, their `max_size()` functions have constant complexity.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code calls `max_size()` on the different value types. Note the output is implementation specific.,max_size}
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::object | ( | std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > > | init = std::initializer_list<basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >>() | ) | [inline, static] |
explicitly create an object from an initializer list
Creates a JSON object value from a given initializer list. The initializer lists elements must be pairs, and their first elements must be strings. If the initializer list is empty, the empty object `{}` is created.
[in] | init | initializer list to create an object from (optional) |
std::domain_error | if init is not a pair whose first elements are strings; thrown by basic_json(std::initializer_list<basic_json>, bool, value_t) |
Linear in the size of init.
{The following code shows an example for the `object` function.,object}
constexpr nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator value_t | ( | ) | const [inline] |
return the type of the JSON value (implicit)
Implicitly return the type of the JSON value as a value from the value_t enumeration.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies the value_t operator for all JSON types.,operator__value_t}
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator ValueType | ( | ) | const [inline] |
get a value (implicit)
Implicit type conversion between the JSON value and a compatible value. The call is realized by calling get() const.
ValueType | non-pointer type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for JSON arrays. The character type of string_t as well as an initializer list of this type is excluded to avoid ambiguities as these types implicitly convert to `std::string`. |
std::domain_error | in case passed type ValueType is incompatible to JSON, thrown by get() const |
Linear in the size of the JSON value.
{The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers\, (2) A JSON array can be converted to a standard `std::vector<short>`\, (3) A JSON object can be converted to C++ associative containers such as `std::unordered_map<std::string\, json>`.,operator__ValueType}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= | ( | basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > && | val | ) | [inline] |
add an object to an array
add an object to an array
Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.
[in] | val | the value to add to the JSON array |
std::domain_error | when called on a type other than JSON array or null; example: `"cannot use push_back() with number"` |
Amortized constant.
{The example shows how `push_back()` and `+=` can be used to add elements to a JSON array. Note how the `null` value was silently converted to a JSON array.,push_back}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= | ( | const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | val | ) | [inline] |
add an object to an array
add an object to an array
Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.
[in] | val | the value to add to the JSON array |
std::domain_error | when called on a type other than JSON array or null; example: `"cannot use push_back() with number"` |
Amortized constant.
{The example shows how `push_back()` and `+=` can be used to add elements to a JSON array. Note how the `null` value was silently converted to a JSON array.,push_back}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= | ( | const typename object_t::value_type & | val | ) | [inline] |
add an object to an object
add an object to an object
Inserts the given element val to the JSON object. If the function is called on a JSON null value, an empty object is created before inserting val.
[in] | val | the value to add to the JSON object |
std::domain_error | when called on a type other than JSON object or null; example: `"cannot use push_back() with number"` |
Logarithmic in the size of the container, O(log(`size()`)).
{The example shows how `push_back()` and `+=` can be used to add elements to a JSON object. Note how the `null` value was silently converted to a JSON object.,push_back__object_t__value}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= | ( | std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > > | init | ) | [inline] |
add an object to an object
add an object to an object
This function allows to use `push_back` with an initializer list. In case
1. the current value is an object, 2. the initializer list init contains only two elements, and 3. the first element of init is a string,
init is converted into an object element and added using push_back(const typename object_t::value_type&). Otherwise, init is converted to a JSON value and added using push_back(basic_json&&).
init | an initializer list |
Linear in the size of the initializer list init.
{The example shows how initializer lists are treated as objects when possible.,push_back__initializer_list}
reference& nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator= | ( | basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > | other | ) | [inline] |
copy assignment
Copy assignment operator. Copies a JSON value via the "copy and swap" strategy: It is expressed in terms of the copy constructor, destructor, and the swap() member function.
[in] | other | value to copy from |
Linear.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The code below shows and example for the copy assignment. It creates a copy of value `a` which is then swapped with `b`. Finally\, the copy of `a` (which is the null value after the swap) is destroyed.,basic_json__copyassignment}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | size_type | idx | ) | [inline] |
access specified array element
Returns a reference to the element at specified location idx.
[in] | idx | index of the element to access |
std::domain_error | if JSON is not an array or null; example: `"cannot use operator[] with string"` |
Constant if idx is in the range of the array. Otherwise linear in `idx - size()`.
{The example below shows how array elements can be read and written using `[]` operator. Note the addition of `null` values.,operatorarray__size_type}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | size_type | idx | ) | const [inline] |
access specified array element
Returns a const reference to the element at specified location idx.
[in] | idx | index of the element to access |
std::domain_error | if JSON is not an array; example: `"cannot use operator[] with null"` |
Constant.
{The example below shows how array elements can be read using the `[]` operator.,operatorarray__size_type_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | const typename object_t::key_type & | key | ) | [inline] |
access specified object element
Returns a reference to the element at with specified key key.
[in] | key | key of the element to access |
std::domain_error | if JSON is not an object or null; example: `"cannot use operator[] with string"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read and written using the `[]` operator.,operatorarray__key_type}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | const typename object_t::key_type & | key | ) | const [inline] |
read-only access specified object element
Returns a const reference to the element at with specified key key. No bounds checking is performed.
[in] | key | key of the element to access |
std::domain_error | if JSON is not an object; example: `"cannot use operator[] with null"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read using the `[]` operator.,operatorarray__key_type_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | T *(&) | key[n] | ) | [inline] |
access specified object element
Returns a reference to the element at with specified key key.
[in] | key | key of the element to access |
std::domain_error | if JSON is not an object or null; example: `"cannot use operator[] with string"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read and written using the `[]` operator.,operatorarray__key_type}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | T *(&) | key[n] | ) | const [inline] |
read-only access specified object element
Returns a const reference to the element at with specified key key. No bounds checking is performed.
[in] | key | key of the element to access |
std::domain_error | if JSON is not an object; example: `"cannot use operator[] with null"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read using the `[]` operator.,operatorarray__key_type_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | T * | key | ) | [inline] |
access specified object element
Returns a reference to the element at with specified key key.
[in] | key | key of the element to access |
std::domain_error | if JSON is not an object or null; example: `"cannot use operator[] with string"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read and written using the `[]` operator.,operatorarray__key_type}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | T * | key | ) | const [inline] |
read-only access specified object element
Returns a const reference to the element at with specified key key. No bounds checking is performed.
[in] | key | key of the element to access |
std::domain_error | if JSON is not an object; example: `"cannot use operator[] with null"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be read using the `[]` operator.,operatorarray__key_type_const}
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | const json_pointer & | ptr | ) | [inline] |
access specified element via JSON Pointer
Uses a JSON pointer to retrieve a reference to the respective JSON value. No bound checking is performed. Similar to operator[](const typename object_t::key_type&), `null` values are created in arrays and objects if necessary.
In particular:
[in] | ptr | a JSON pointer |
Constant.
std::out_of_range | if the JSON pointer can not be resolved |
std::domain_error | if an array index begins with '0' |
std::invalid_argument | if an array index was not a number |
{The behavior is shown in the example.,operatorjson_pointer}
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] | ( | const json_pointer & | ptr | ) | const [inline] |
access specified element via JSON Pointer
Uses a JSON pointer to retrieve a reference to the respective JSON value. No bound checking is performed. The function does not change the JSON value; no `null` values are created. In particular, the the special value `-` yields an exception.
[in] | ptr | JSON pointer to the desired element |
Constant.
std::out_of_range | if the JSON pointer can not be resolved |
std::domain_error | if an array index begins with '0' |
std::invalid_argument | if an array index was not a number |
{The behavior is shown in the example.,operatorjson_pointer_const}
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parse | ( | const string_t & | s, |
parser_callback_t | cb = nullptr |
||
) | [inline, static] |
deserialize from string
[in] | s | string to read a serialized JSON value from |
[in] | cb | a parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional) |
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
{The example below demonstrates the `parse()` function with and without callback function.,parse__string__parser_callback_t}
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parse | ( | std::istream & | i, |
parser_callback_t | cb = nullptr |
||
) | [inline, static] |
deserialize from stream
[in,out] | i | stream to read a serialized JSON value from |
[in] | cb | a parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional) |
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
{The example below demonstrates the `parse()` function with and without callback function.,parse__istream__parser_callback_t}
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parse | ( | std::istream && | i, |
parser_callback_t | cb = nullptr |
||
) | [inline, static] |
deserialize from stream
[in,out] | i | stream to read a serialized JSON value from |
[in] | cb | a parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional) |
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
{The example below demonstrates the `parse()` function with and without callback function.,parse__istream__parser_callback_t}
basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::patch | ( | const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | json_patch | ) | const [inline] |
applies a JSON patch
[JSON Patch](http://jsonpatch.com) defines a JSON document structure for expressing a sequence of operations to apply to a JSON) document. With this funcion, a JSON Patch is applied to the current JSON value by executing all operations from the patch.
[in] | json_patch | JSON patch document |
std::out_of_range | if a JSON pointer inside the patch could not be resolved successfully in the current JSON value; example: `"key baz not found"` |
invalid_argument | if the JSON patch is malformed (e.g., mandatory attributes are missing); example: `"operation add must have member path"` |
Linear in the size of the JSON value and the length of the JSON patch. As usually only a fraction of the JSON value is affected by the patch, the complexity can usually be neglected.
{The following code shows how a JSON patch is applied to a value.,patch}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::push_back | ( | basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > && | val | ) | [inline] |
add an object to an array
Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.
[in] | val | the value to add to the JSON array |
std::domain_error | when called on a type other than JSON array or null; example: `"cannot use push_back() with number"` |
Amortized constant.
{The example shows how `push_back()` and `+=` can be used to add elements to a JSON array. Note how the `null` value was silently converted to a JSON array.,push_back}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::push_back | ( | const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | val | ) | [inline] |
add an object to an array
add an object to an array
Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.
[in] | val | the value to add to the JSON array |
std::domain_error | when called on a type other than JSON array or null; example: `"cannot use push_back() with number"` |
Amortized constant.
{The example shows how `push_back()` and `+=` can be used to add elements to a JSON array. Note how the `null` value was silently converted to a JSON array.,push_back}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::push_back | ( | const typename object_t::value_type & | val | ) | [inline] |
add an object to an object
Inserts the given element val to the JSON object. If the function is called on a JSON null value, an empty object is created before inserting val.
[in] | val | the value to add to the JSON object |
std::domain_error | when called on a type other than JSON object or null; example: `"cannot use push_back() with number"` |
Logarithmic in the size of the container, O(log(`size()`)).
{The example shows how `push_back()` and `+=` can be used to add elements to a JSON object. Note how the `null` value was silently converted to a JSON object.,push_back__object_t__value}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::push_back | ( | std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > > | init | ) | [inline] |
add an object to an object
This function allows to use `push_back` with an initializer list. In case
1. the current value is an object, 2. the initializer list init contains only two elements, and 3. the first element of init is a string,
init is converted into an object element and added using push_back(const typename object_t::value_type&). Otherwise, init is converted to a JSON value and added using push_back(basic_json&&).
init | an initializer list |
Linear in the size of the initializer list init.
{The example shows how initializer lists are treated as objects when possible.,push_back__initializer_list}
reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::rbegin | ( | ) | [inline] |
returns an iterator to the reverse-beginning
Returns an iterator to the reverse-beginning; that is, the last element.
Constant.
This function helps `basic_json` satisfying the [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirements:
{The following code shows an example for `rbegin()`.,rbegin}
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::rbegin | ( | ) | const [inline] |
returns a const reverse iterator to the last element
Returns a const iterator to the reverse-beginning; that is, the last element.
Constant.
This function helps `basic_json` satisfying the [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirements:
{The following code shows an example for `crbegin()`.,crbegin}
reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::rend | ( | ) | [inline] |
returns an iterator to the reverse-end
Returns an iterator to the reverse-end; that is, one before the first element.
Constant.
This function helps `basic_json` satisfying the [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirements:
{The following code shows an example for `rend()`.,rend}
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::rend | ( | ) | const [inline] |
returns a const reverse iterator to one before the first
Returns a const reverse iterator to the reverse-end; that is, one before the first element.
Constant.
This function helps `basic_json` satisfying the [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) requirements:
{The following code shows an example for `crend()`.,crend}
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::size | ( | ) | const [inline] |
returns the number of elements
Returns the number of elements in a JSON value.
Constant, as long as array_t and object_t satisfy the Container concept; that is, their size() functions have constant complexity.
This function helps `basic_json` satisfying the [Container](http://en.cppreference.com/w/cpp/concept/Container) requirements:
{The following code calls `size()` on the different value types.,size}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap | ( | reference | other | ) | [inline] |
exchanges the values
Exchanges the contents of the JSON value with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
[in,out] | other | JSON value to exchange the contents with |
Constant.
{The example below shows how JSON values can be swapped with `swap()`.,swap__reference}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap | ( | array_t & | other | ) | [inline] |
exchanges the values
Exchanges the contents of a JSON array with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
[in,out] | other | array to exchange the contents with |
std::domain_error | when JSON value is not an array; example: `"cannot use swap() with string"` |
Constant.
{The example below shows how arrays can be swapped with `swap()`.,swap__array_t}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap | ( | object_t & | other | ) | [inline] |
exchanges the values
Exchanges the contents of a JSON object with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
[in,out] | other | object to exchange the contents with |
std::domain_error | when JSON value is not an object; example: `"cannot use swap() with string"` |
Constant.
{The example below shows how objects can be swapped with `swap()`.,swap__object_t}
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap | ( | string_t & | other | ) | [inline] |
exchanges the values
Exchanges the contents of a JSON string with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
[in,out] | other | string to exchange the contents with |
std::domain_error | when JSON value is not a string; example: `"cannot use swap() with boolean"` |
Constant.
{The example below shows how strings can be swapped with `swap()`.,swap__string_t}
constexpr value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::type | ( | ) | const [inline] |
return the type of the JSON value (explicit)
Return the type of the JSON value as a value from the value_t enumeration.
Constant.
No-throw guarantee: this member function never throws exceptions.
{The following code exemplifies `type()` for all JSON types.,type}
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::type_name | ( | ) | const [inline, private] |
basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::unflatten | ( | ) | const [inline] |
unflatten a previously flattened JSON value
The function restores the arbitrary nesting of a JSON value that has been flattened before using the flatten() function. The JSON value must meet certain constraints: 1. The value must be an object. 2. The keys must be JSON pointers (see [RFC 6901](https://tools.ietf.org/html/rfc6901)) 3. The mapped values must be primitive JSON types.
Linear in the size the JSON value.
{The following code shows how a flattened JSON object is unflattened into the original nested JSON object.,unflatten}
ValueType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::value | ( | const typename object_t::key_type & | key, |
ValueType | default_value | ||
) | const [inline] |
access specified object element with default value
Returns either a copy of an object's element at the specified key key or a given default value if no element with key key exists.
The function is basically equivalent to executing
{.cpp} try { return at(key); } catch(std::out_of_range) { return default_value; }
[in] | key | key of the element to access |
[in] | default_value | the value to return if key is not found |
ValueType | type compatible to JSON values, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for JSON arrays. Note the type of the expected value at key and the default value default_value must be compatible. |
std::domain_error | if JSON is not an object; example: `"cannot use value() with null"` |
Logarithmic in the size of the container.
{The example below shows how object elements can be queried with a default value.,basic_json__value}
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::value | ( | const typename object_t::key_type & | key, |
const char * | default_value | ||
) | const [inline] |
bool operator!= | ( | const_reference | lhs, |
const_reference | rhs | ||
) | [friend] |
comparison: not equal
Compares two JSON values for inequality by calculating `not (lhs == rhs)`.
[in] | lhs | first JSON value to consider |
[in] | rhs | second JSON value to consider |
Linear.
{The example demonstrates comparing several JSON types.,operator__notequal}
bool operator!= | ( | const_reference | v, |
std::nullptr_t | |||
) | [friend] |
comparison: not equal
The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call `not v.is_null()`.
[in] | v | JSON value to consider |
Constant.
{The example compares several JSON types to the null pointer. ,operator__notequal__nullptr_t}
bool operator!= | ( | std::nullptr_t | , |
const_reference | v | ||
) | [friend] |
comparison: not equal
comparison: not equal
The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call `not v.is_null()`.
[in] | v | JSON value to consider |
Constant.
{The example compares several JSON types to the null pointer. ,operator__notequal__nullptr_t}
bool operator< | ( | const value_t | lhs, |
const value_t | rhs | ||
) | [friend] |
bool operator< | ( | const_reference | lhs, |
const_reference | rhs | ||
) | [friend] |
comparison: less than
Compares whether one JSON value lhs is less than another JSON value rhs according to the following rules:
[in] | lhs | first JSON value to consider |
[in] | rhs | second JSON value to consider |
Linear.
{The example demonstrates comparing several JSON types.,operator__less}
std::ostream& operator<< | ( | std::ostream & | o, |
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | j | ||
) | [friend] |
serialize to stream
Serialize the given JSON value j to the output stream o. The JSON value will be serialized using the dump member function. The indentation of the output can be controlled with the member variable `width` of the output stream o. For instance, using the manipulator `std::setw(4)` on o sets the indentation level to `4` and the serialization result is the same as calling `dump(4)`.
[in,out] | o | stream to serialize to |
[in] | j | JSON value to serialize |
Linear.
{The example below shows the serialization with different parameters to `width` to adjust the indentation level.,operator_serialize}
std::istream& operator<< | ( | basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | j, |
std::istream & | i | ||
) | [friend] |
deserialize from stream
Deserializes an input stream to a JSON value.
[in,out] | i | input stream to read a serialized JSON value from |
[in,out] | j | JSON value to write the deserialized input to |
std::invalid_argument | in case of parse errors |
Linear in the length of the input. The parser is a predictive LL(1) parser.
{The example below shows how a JSON value is constructed by reading a serialization from a stream.,operator_deserialize}
bool operator<= | ( | const_reference | lhs, |
const_reference | rhs | ||
) | [friend] |
comparison: less than or equal
Compares whether one JSON value lhs is less than or equal to another JSON value by calculating `not (rhs < lhs)`.
[in] | lhs | first JSON value to consider |
[in] | rhs | second JSON value to consider |
Linear.
{The example demonstrates comparing several JSON types.,operator__greater}
bool operator== | ( | const_reference | lhs, |
const_reference | rhs | ||
) | [friend] |
comparison: equal
Compares two JSON values for equality according to the following rules:
[in] | lhs | first JSON value to consider |
[in] | rhs | second JSON value to consider |
Linear.
{The example demonstrates comparing several JSON types.,operator__equal}
bool operator== | ( | const_reference | v, |
std::nullptr_t | |||
) | [friend] |
comparison: equal
The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call `v.is_null()`.
[in] | v | JSON value to consider |
Constant.
{The example compares several JSON types to the null pointer. ,operator__equal__nullptr_t}
bool operator== | ( | std::nullptr_t | , |
const_reference | v | ||
) | [friend] |
comparison: equal
comparison: equal
The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call `v.is_null()`.
[in] | v | JSON value to consider |
Constant.
{The example compares several JSON types to the null pointer. ,operator__equal__nullptr_t}
bool operator> | ( | const_reference | lhs, |
const_reference | rhs | ||
) | [friend] |
comparison: greater than
Compares whether one JSON value lhs is greater than another JSON value by calculating `not (lhs <= rhs)`.
[in] | lhs | first JSON value to consider |
[in] | rhs | second JSON value to consider |
Linear.
{The example demonstrates comparing several JSON types.,operator__lessequal}
bool operator>= | ( | const_reference | lhs, |
const_reference | rhs | ||
) | [friend] |
comparison: greater than or equal
Compares whether one JSON value lhs is greater than or equal to another JSON value by calculating `not (lhs < rhs)`.
[in] | lhs | first JSON value to consider |
[in] | rhs | second JSON value to consider |
Linear.
{The example demonstrates comparing several JSON types.,operator__greaterequal}
std::ostream& operator>> | ( | const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | j, |
std::ostream & | o | ||
) | [friend] |
serialize to stream
serialize to stream
Serialize the given JSON value j to the output stream o. The JSON value will be serialized using the dump member function. The indentation of the output can be controlled with the member variable `width` of the output stream o. For instance, using the manipulator `std::setw(4)` on o sets the indentation level to `4` and the serialization result is the same as calling `dump(4)`.
[in,out] | o | stream to serialize to |
[in] | j | JSON value to serialize |
Linear.
{The example below shows the serialization with different parameters to `width` to adjust the indentation level.,operator_serialize}
std::istream& operator>> | ( | std::istream & | i, |
basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > & | j | ||
) | [friend] |
deserialize from stream
deserialize from stream
Deserializes an input stream to a JSON value.
[in,out] | i | input stream to read a serialized JSON value from |
[in,out] | j | JSON value to write the deserialized input to |
std::invalid_argument | in case of parse errors |
Linear in the length of the input. The parser is a predictive LL(1) parser.
{The example below shows how a JSON value is constructed by reading a serialization from a stream.,operator_deserialize}
value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::m_type = value_t::null [private] |
json_value nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::m_value = {} [private] |