1# basic_json 2 3Defined in header `<json.hpp>` 4 5```cpp 6template< 7 template<typename U, typename V, typename... Args> class ObjectType = std::map, 8 template<typename U, typename... Args> class ArrayType = std::vector, 9 class StringType = std::string, 10 class BooleanType = bool, 11 class NumberIntegerType = std::int64_t, 12 class NumberUnsignedType = std::uint64_t, 13 class NumberFloatType = double, 14 template<typename U> class AllocatorType = std::allocator, 15 template<typename T, typename SFINAE = void> class JSONSerializer = adl_serializer, 16 class BinaryType = std::vector<std::uint8_t> 17> 18class basic_json; 19``` 20 21## Specializations 22 23- [**json**](../json.md) - default specialization 24- [**ordered_json**](../ordered_json.md) - specialization that maintains the insertion order of object keys 25 26## Template parameters 27 28| Template parameter | Description | Derived type | 29| -------------------- | ----------- | ------------ | 30| `ObjectType` | type for JSON objects | [`object_t`](object_t.md) | 31| `ArrayType` | type for JSON arrays | [`array_t`](array_t.md) | 32| `StringType` | type for JSON strings and object keys | [`string_t`](string_t.md) | 33| `BooleanType` | type for JSON booleans | [`boolean_t`](boolean_t.md) | 34| `NumberIntegerType` | type for JSON integer numbers | [`number_integer_t`](number_integer_t.md) | 35| `NumberUnsignedType` | type for JSON unsigned integer numbers | [`number_unsigned_t`](number_unsigned_t.md) | 36| `NumberFloatType` | type for JSON floating-point numbers | [`number_float_t`](number_float_t.md) | 37| `AllocatorType` | type of the allocator to use | | 38| `JSONSerializer` | the serializer to resolve internal calls to `to_json()` and `from_json()` | [`json_serializer`](json_serializer.md) | 39| `BinaryType` | type for binary arrays | [`binary_t`](binary_t.md) | 40 41## Iterator invalidation 42 43Todo 44 45## Member types 46 47- [**adl_serializer**](../adl_serializer.md) - the default serializer 48- [**value_t**](value_t.md) - the JSON type enumeration 49- [**json_pointer**](../json_pointer.md) - JSON Pointer implementation 50- [**json_serializer**](json_serializer.md) - type of the serializer to for conversions from/to JSON 51- [**error_handler_t**](error_handler_t.md) - type to choose behavior on decoding errors 52- [**cbor_tag_handler_t**](cbor_tag_handler_t.md) - type to choose how to handle CBOR tags 53- initializer_list_t 54- [**input_format_t**](input_format_t.md) - type to choose the format to parse 55- json_sax_t 56 57### Exceptions 58 59- [**exception**](exception.md) - general exception of the `basic_json` class 60 - [**parse_error**](parse_error.md) - exception indicating a parse error 61 - [**invalid_iterator**](invalid_iterator.md) - exception indicating errors with iterators 62 - [**type_error**](type_error.md) - exception indicating executing a member function with a wrong type 63 - [**out_of_range**](out_of_range.md) - exception indicating access out of the defined range 64 - [**other_error**](other_error.md) - exception indicating other library errors 65 66### Container types 67 68| Type | Definition | 69| ------------------------ | ---------- | 70| `value_type` | `#!cpp basic_json` | 71| `reference` | `#!cpp value_type&` | 72| `const_reference` | `#!cpp const value_type&` | 73| `difference_type` | `#!cpp std::ptrdiff_t` | 74| `size_type` | `#!cpp std::size_t` | 75| `allocator_type` | `#!cpp AllocatorType<basic_json>` | 76| `pointer` | `#!cpp std::allocator_traits<allocator_type>::pointer` | 77| `const_pointer` | `#!cpp std::allocator_traits<allocator_type>::const_pointer` | 78| `iterator` | [LegacyBidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator) | 79| `const_iterator` | constant [LegacyBidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator) | 80| `reverse_iterator` | reverse iterator, derived from `iterator` | 81| `const_reverse_iterator` | reverse iterator, derived from `const_iterator` | 82| `iteration_proxy` | helper type for [`items`](items.md) function | 83 84### JSON value data types 85 86- [**array_t**](array_t.md) - type for arrays 87- [**binary_t**](binary_t.md) - type for binary arrays 88- [**boolean_t**](boolean_t.md) - type for booleans 89- [**number_float_t**](number_float_t.md) - type for numbers (floating-point) 90- [**number_integer_t**](number_integer_t.md) - type for numbers (integer) 91- [**number_unsigned_t**](number_unsigned_t.md) - type for numbers (unsigned) 92- [**object_comparator_t**](object_comparator_t.md) - comparator for objects 93- [**object_t**](object_t.md) - type for objects 94- [**string_t**](string_t.md) - type for strings 95 96### Parser callback 97 98- [**parse_event_t**](parse_event_t.md) - parser event types 99- [**parser_callback_t**](parser_callback_t.md) - per-element parser callback type 100 101## Member functions 102 103- [(constructor)](basic_json.md) 104- [(destructor)](~basic_json.md) 105- [**operator=**](operator=.md) - copy assignment 106- [**array**](array_t.md) (static) - explicitly create an array 107- [**binary**](binary.md) (static) - explicitly create a binary array 108- [**object**](object_t.md) (static) - explicitly create an object 109 110### Object inspection 111 112Functions to inspect the type of a JSON value. 113 114- [**type**](type.md) - return the type of the JSON value 115- [**operator value_t**](operator_value_t.md) - return the type of the JSON value 116- [**type_name**](type_name.md) - return the type as string 117- [**is_primitive**](is_primitive.md) - return whether type is primitive 118- [**is_structured**](is_structured.md) - return whether type is structured 119- [**is_null**](is_null.md) - return whether value is null 120- [**is_boolean**](is_boolean.md) - return whether value is a boolean 121- [**is_number**](is_number.md) - return whether value is a number 122- [**is_number_integer**](is_number_integer.md) - return whether value is an integer number 123- [**is_number_unsigned**](is_number_unsigned.md) - return whether value is an unsigned integer number 124- [**is_number_float**](is_number_float.md) - return whether value is a floating-point number 125- [**is_object**](is_object.md) - return whether value is an object 126- [**is_array**](is_array.md) - return whether value is an array 127- [**is_string**](is_string.md) - return whether value is a string 128- [**is_binary**](is_binary.md) - return whether value is a binary array 129- [**is_discarded**](is_discarded.md) - return whether value is discarded 130 131### Value access 132 133Direct access to the stored value of a JSON value. 134 135- [**get**](get.md) - get a value 136- [**get_to**](get_to.md) - get a value and write it to a destination 137- [**get_ptr**](get_ptr.md) - get a pointer value 138- [**get_ref**](get_ref.md) - get a reference value 139- [**operator ValueType**](operator_ValueType.md) - get a value 140- [**get_binary**](get_binary.md) - get a binary value 141 142### Element access 143 144Access to the JSON value 145 146- [**at**](at.md) - access specified element with bounds checking 147- [**operator[]**](operator[].md) - access specified element 148- [**value**](value.md) - access specified object element with default value 149- [**front**](front.md) - access the first element 150- [**back**](back.md) - access the last element 151 152### Lookup 153 154- [**find**](find.md) - find an element in a JSON object 155- [**count**](count.md) - returns the number of occurrences of a key in a JSON object 156- [**contains**](contains.md) - check the existence of an element in a JSON object 157 158### Iterators 159 160- [**begin**](begin.md) - returns an iterator to the first element 161- [**cbegin**](cbegin.md) - returns a const iterator to the first element 162- [**end**](end.md) - returns an iterator to one past the last element 163- [**cend**](cend.md) - returns a const iterator to one past the last element 164- [**rbegin**](rbegin.md) - returns an iterator to the reverse-beginning 165- [**rend**](rend.md) - returns an iterator to the reverse-end 166- [**crbegin**](crbegin.md) - returns a const iterator to the reverse-beginning 167- [**crend**](crend.md) - returns a const iterator to the reverse-end 168- [**items**](items.md) - wrapper to access iterator member functions in range-based for 169 170### Capacity 171 172- [**empty**](empty.md) - checks whether the container is empty 173- [**size**](size.md) - returns the number of elements 174- [**max_size**](max_size.md) - returns the maximum possible number of elements 175 176### Modifiers 177 178- [**clear**](clear.md) - clears the contents 179- [**push_back**](push_back.md) - add a value to an array/object 180- [**operator+=**](operator+=.md) - add a value to an array/object 181- [**emplace_back**](emplace_back.md) - add a value to an array 182- [**emplace**](emplace.md) - add a value to an object if key does not exist 183- [**erase**](erase.md) - remove elements 184- [**insert**](insert.md) - inserts elements 185- [**update**](update.md) - updates a JSON object from another object, overwriting existing keys 186- swap - exchanges the values 187 188### Lexicographical comparison operators 189 190- [**operator==**](operator_eq.md) - comparison: equal 191- [**operator!=**](operator_ne.md) - comparison: not equal 192- [**operator<**](operator_lt.md) - comparison: less than 193- [**operator<=**](operator_le.md) - comparison: less than or equal 194- [**operator>**](operator_gt.md) - comparison: greater than 195- [**operator>=**](operator_ge.md) - comparison: greater than or equal 196 197### Serialization / Dumping 198 199- [**dump**](dump.md) - serialization 200- to_string - user-defined to_string function for JSON values 201 202### Deserialization / Parsing 203 204- [**parse**](parse.md) (static) - deserialize from a compatible input 205- [**accept**](accept.md) (static) - check if the input is valid JSON 206- [**sax_parse**](sax_parse.md) (static) - generate SAX events 207 208### JSON Pointer functions 209 210- [**flatten**](flatten.md) - return flattened JSON value 211- [**unflatten**](unflatten.md) - unflatten a previously flattened JSON value 212 213### JSON Patch functions 214 215- [**patch**](patch.md) - applies a JSON patch 216- [**diff**](diff.md) (static) - creates a diff as a JSON patch 217 218### JSON Merge Patch functions 219 220- [**merge_patch**](merge_patch.md) - applies a JSON Merge Patch 221 222## Static functions 223 224- [**meta**](meta.md) - returns version information on the library 225- [**get_allocator**](get_allocator.md) - returns the allocator associated with the container 226 227### Binary formats 228 229- [**from_bson**](from_bson.md) (static) - create a JSON value from an input in BSON format 230- [**from_cbor**](from_cbor.md) (static) - create a JSON value from an input in CBOR format 231- [**from_msgpack**](from_msgpack.md) (static) - create a JSON value from an input in MessagePack format 232- [**from_ubjson**](from_ubjson.md) (static) - create a JSON value from an input in UBJSON format 233- [**to_bson**](to_bson.md) (static) - create a BSON serialization of a given JSON value 234- [**to_cbor**](to_cbor.md) (static) - create a CBOR serialization of a given JSON value 235- [**to_msgpack**](to_msgpack.md) (static) - create a MessagePack serialization of a given JSON value 236- [**to_ubjson**](to_ubjson.md) (static) - create a UBJSON serialization of a given JSON value 237 238## Non-member functions 239 240- operator<<(std::ostream&) - serialize to stream 241- operator>>(std::istream&) - deserialize from stream 242 243## Literals 244 245- [**operator""_json**](operator_literal_json.md) - user-defined string literal for JSON values 246- [**operator""_json_pointer**](operator_literal_json_pointer.md) - user-defined string literal for JSON pointers 247 248## Helper classes 249 250- std::hash<nlohmann::json\> 251- std::less<nlohmann::value_t\> 252- std::swap<nlohmann::json\> 253