nlohmann::basic_json

a class to store JSON values

Synopsis

Declared in <nlohmann/json.hpp>
template<
    template<
    typename U,
    typename V,
    typename... Args> typename ObjectType = map,
    template<
    typename U,
    typename... Args> typename ArrayType = vector,
    class StringType = std::string,
    class BooleanType = bool,
    class NumberIntegerType = int64_t,
    class NumberUnsignedType = uint64_t,
    class NumberFloatType = double,
    template<typename U> typename AllocatorType = allocator,
    template<
    typename T,
    typename SFINAE = void> typename JSONSerializer = adl_serializer,
    class BinaryType = std::vector<uint8_t>,
    class CustomBaseClass = void>
class basic_json
    : public nlohmann::detail::json_base_class<CustomBaseClass>


Base Classes

Name Description
nlohmann::detail::json_base_class<CustomBaseClass>

Types

Name Description
allocator_type the allocator type
array_t a type for an array
binary_t a type for a packed binary type
bjdata_version_t how to encode BJData
boolean_t a type for a boolean
cbor_tag_handler_t how to treat CBOR tags
const_iterator a const iterator for a basic_json container
const_pointer the type of an element const pointer
const_reference the type of an element const reference
const_reverse_iterator a const reverse iterator for a basic_json container
default_object_comparator_t
difference_type a type to represent differences between iterators
error_handler_t how to treat decoding errors
exception Classes to implement user-defined exceptions. @{
initializer_list_t helper type for initializer lists of basic_json values
input_format_t
invalid_iterator
iterator an iterator for a basic_json container
json_pointer JSON Pointer, see nlohmann::json_pointer
json_sax_t SAX interface type, see nlohmann::json_sax
json_serializer
number_float_t a type for a number (floating-point)
number_integer_t a type for a number (integer)
number_unsigned_t a type for a number (unsigned)
object_comparator_t object key comparator type
object_t a type for an object
other_error
out_of_range
parse_error
parse_event_t parser event types
parser_callback_t per-element parser callback type
pointer the type of an element pointer
reference the type of an element reference
reverse_iterator a reverse iterator for a basic_json container
size_type a type to represent container sizes
string_t a type for a string
type_error
value_t
value_type the type of elements in a basic_json container

Member Functions

Name Description
basic_json [constructor]copy constructor
basic_json [constructor]move constructor
basic_json [constructor]create a null object
basic_json [constructor]create an empty value with a given type
basic_json [constructor]create a JSON value from an existing one
basic_json [constructor]////////////////////////////////////
basic_json [constructor]create a JSON value from compatible types
basic_json [constructor]construct an array with count copies of given value
basic_json [constructor]construct a JSON container given an iterator range
basic_json [constructor]create a container (array or object) from an initializer list
~basic_json [destructor]destructor
operator= copy assignment
at access specified array element with bounds checking
at access specified array element with bounds checking
at access specified element via JSON Pointer
at access specified element via JSON Pointer
at access specified object element with bounds checking
at access specified object element with bounds checking
at
at
at access specified object element with bounds checking
at access specified object element with bounds checking
back access the last element
back access the last element
begin returns an iterator to the first element
begin returns an iterator to the first element
cbegin returns a const iterator to the first element
cend returns an iterator to one past the last element
clear clears the contents
contains check the existence of an element in a JSON object given a JSON pointer
contains check the existence of an element in a JSON object
contains
contains check the existence of an element in a JSON object
count returns the number of occurrences of a key in a JSON object
count returns the number of occurrences of a key in a JSON object
crbegin returns a const reverse iterator to the last element
crend returns a const reverse iterator to one before the first
dump serialization
emplace add an object to an object if key does not exist
emplace_back add an object to an array
empty checks whether the container is empty.
end returns an iterator to one past the last element
end returns an iterator to one past the last element
erase remove element from a JSON array given an index
erase remove element from a JSON object given a key
erase remove element given an iterator
erase remove element from a JSON object given a key
erase remove elements given an iterator range
find find an element in a JSON object
find find an element in a JSON object
find find an element in a JSON object
find find an element in a JSON object
flatten return flattened JSON value
front access the first element
front access the first element
get get a pointer value (explicit)
get get a (pointer) value (explicit)
get_binary get a binary value
get_binary get a binary value
get_ptr get a pointer value (implicit)
get_ptr get a pointer value (implicit)
get_ref get a reference value (implicit)
get_ref get a reference value (implicit)
get_to get a value (explicit)
get_to
get_to
insert inserts range of elements into object
insert inserts elements from initializer list into array
insert inserts element into array
insert inserts element into array
insert inserts range of elements into array
insert inserts copies of element into array
insert_iterator Helper for insertion of an iterator
is_array return whether value is an array
is_binary return whether value is a binary array
is_boolean return whether value is a boolean
is_discarded return whether value is discarded
is_null return whether value is null
is_number return whether value is a number
is_number_float return whether value is a floating-point number
is_number_integer return whether value is an integer number
is_number_unsigned return whether value is an unsigned integer number
is_object return whether value is an object
is_primitive return whether type is primitive
is_string return whether value is a string
is_structured return whether type is structured
items helper to access iterator member functions in range-based for
items helper to access iterator member functions in range-based for
max_size returns the maximum possible number of elements
merge_patch applies a JSON Merge Patch
operator+= add an object to an object
operator+= add an object to an array
operator+= add an object to an object
operator+= add an object to an array
operator[] access specified object element
operator[] access specified array element
operator[] access specified array element
operator[] access specified element via JSON Pointer
operator[] access specified element via JSON Pointer
operator[] access specified object element
operator[] Subscript operator
operator[] Subscript operator
operator[] access specified object element
operator[] access specified object element
operator[] Subscript operator
operator[] Subscript operator
patch applies a JSON patch to a copy of the current object
patch_inplace applies a JSON patch in-place without copying the object
push_back add an object to an object
push_back add an object to an array
push_back add an object to an object
push_back add an object to an array
rbegin returns an iterator to the reverse-beginning
rbegin returns an iterator to the reverse-beginning
rend returns an iterator to the reverse-end
rend returns an iterator to the reverse-end
size returns the number of elements
swap exchanges the values
swap exchanges the values
swap exchanges the values
swap exchanges the values
swap exchanges the values
swap exchanges the values
type return the type of the JSON value (explicit)
type_name return the type as string
unflatten unflatten a previously flattened JSON value
update updates a JSON object from another object, overwriting existing keys
update updates a JSON object from another object, overwriting existing keys
value access specified object element via JSON Pointer with default value
value access specified object element with default value
value access specified object element via JSON Pointer with default value
value access specified object element with default value
value
value access specified object element with default value
value
value access specified object element via JSON Pointer with default value
operator ValueType get a value (implicit)
operator value_t return the type of the JSON value (implicit)
operator== comparison: equal
operator== comparison: equal
operator!= comparison: not equal
operator<=> comparison: 3-way
operator<=> comparison: 3-way

Static Member Functions

Name Description
accept
accept check if the input is valid JSON
accept check if the input is valid JSON
array explicitly create an array from an initializer list
binary explicitly create a binary array (without subtype)
binary explicitly create a binary array
binary explicitly create a binary array (with subtype)
binary explicitly create a binary array (with subtype)
diff creates a diff as a JSON patch
from_bjdata create a JSON value from an input in BJData format
from_bjdata create a JSON value from an input in BJData format
from_bson
from_bson create a JSON value from an input in BSON format
from_bson create a JSON value from an input in BSON format
from_bson
from_cbor
from_cbor create a JSON value from an input in CBOR format
from_cbor create a JSON value from an input in CBOR format
from_cbor
from_msgpack
from_msgpack create a JSON value from an input in MessagePack format
from_msgpack create a JSON value from an input in MessagePack format
from_msgpack
from_ubjson
from_ubjson create a JSON value from an input in UBJSON format
from_ubjson create a JSON value from an input in UBJSON format
from_ubjson
get_allocator returns the allocator associated with the container
iterator_wrapper wrapper to access iterator member functions in range-based for
iterator_wrapper wrapper to access iterator member functions in range-based for
meta returns version information on the library
object explicitly create an object from an initializer list
parse
parse deserialize from a compatible input
parse deserialize from a pair of character iterators
sax_parse generate SAX events
sax_parse generate SAX events
sax_parse generate SAX events
to_bjdata create a BJData serialization of a given JSON value
to_bjdata create a BJData serialization of a given JSON value
to_bjdata create a BJData serialization of a given JSON value
to_bson create a BSON serialization of a given JSON value
to_bson create a BSON serialization of a given JSON value
to_bson create a BSON serialization of a given JSON value
to_cbor create a CBOR serialization of a given JSON value
to_cbor create a CBOR serialization of a given JSON value
to_cbor create a CBOR serialization of a given JSON value
to_msgpack create a MessagePack serialization of a given JSON value
to_msgpack create a MessagePack serialization of a given JSON value
to_msgpack create a MessagePack serialization of a given JSON value
to_ubjson create a UBJSON serialization of a given JSON value
to_ubjson create a UBJSON serialization of a given JSON value
to_ubjson create a UBJSON serialization of a given JSON value

Friends

|===
Name Description
operator>> deserialize from stream
operator<< deserialize from stream
operator>> serialize to stream
operator<< serialize to stream
swap exchanges the values
exception general exception of the basic_json class
serializer
json_pointer

Non-Member Functions

Name Description
operator<<deserialize from stream
operator>>serialize to stream
to_stringuser-defined to_string function for JSON values

Description

a class to store JSON values

@invariant The member variables @a m_value and @a m_type have the following relationship: - If `m_type == value_t::object`, then `m_value.object != nullptr`. - If `m_type == value_t::array`, then `m_value.array != nullptr`. - If `m_type == value_t::string`, then `m_value.string != nullptr`. The invariants are checked by member function assert_invariant(). @note ObjectType trick from https://stackoverflow.com/a/9860911

Created with MrDocs