JSON for Modern C++ 3.8.0

Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
nlohmann::basic_json Class Reference

a class to store JSON values More...

`#include <json.hpp>`

## Public Types
using | cbor_tag_handler_t = detail::cbor_tag_handler_t
| how to treat CBOR tags More...
using | error_handler_t = detail::error_handler_t
| how to treat decoding errors More...
using | initializer_list_t = std::initializer_list< detail::json_ref< basic_json > >
| helper type for initializer lists of basic_json values More...
using | input_format_t = detail::input_format_t
using | json_pointer = ::nlohmann::json_pointer< basic_json >
| JSON Pointer, see nlohmann::json_pointer. More...
using | json_sax_t = json_sax< basic_json >
| SAX interface type, see nlohmann::json_sax. More...
template<typename T , typename SFINAE >
using | json_serializer = JSONSerializer< T, SFINAE >
using | parse_event_t = detail::parse_event_t
| parser event types More...
using | parser_callback_t = detail::parser_callback_t< basic_json >
| per-element parser callback type More...
using | value_t = detail::value_t

## Public Member Functions
const char * | type_name () const noexcept
| return the type as string More...

## Static Public Member Functions
static allocator_type | get_allocator ()
| returns the allocator associated with the container More...
static basic_json | meta ()
| returns version information on the library More...

## Friends
template<detail::value_t >
struct | detail::external_constructor

## exceptions
Classes to implement user-defined exceptions.
using | exception = detail::exception
| general exception of the basic_json class More...
using | parse_error = detail::parse_error
| exception indicating a parse error More...
using | invalid_iterator = detail::invalid_iterator
| exception indicating errors with iterators More...
using | type_error = detail::type_error
| exception indicating executing a member function with a wrong type More...
using | out_of_range = detail::out_of_range
| exception indicating access out of the defined range More...
using | other_error = detail::other_error
| exception indicating other library errors More...

## container types
The canonic container types to use basic_json like any other STL container.
using | value_type = basic_json
| the type of elements in a basic_json container More...
using | reference = value_type &
| the type of an element reference More...
using | const_reference = const value_type &
| the type of an element const reference More...
using | difference_type = std::ptrdiff_t
| a type to represent differences between iterators More...
using | size_type = std::size_t
| a type to represent container sizes More...
using | allocator_type = AllocatorType< basic_json >
| the allocator type More...
using | pointer = typename std::allocator_traits< allocator_type >::pointer
| the type of an element pointer More...
using | const_pointer = typename std::allocator_traits< allocator_type >::const_pointer
| the type of an element const pointer More...
using | iterator = iter_impl< basic_json >
| an iterator for a basic_json container More...
using | const_iterator = iter_impl< const basic_json >
| a const iterator for a basic_json container More...
using | reverse_iterator = json_reverse_iterator< typename basic_json::iterator >
| a reverse iterator for a basic_json container More...
using | const_reverse_iterator = json_reverse_iterator< typename basic_json::const_iterator >
| a const reverse iterator for a basic_json container More...

## JSON value data types
The data types to store a JSON value. These types are derived from the template arguments passed to class basic_json.
using | object_comparator_t = std::less< StringType >
using | object_t = ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >>
| a type for an object More...
using | array_t = ArrayType< basic_json, AllocatorType< basic_json > >
| a type for an array More...
using | string_t = StringType
| a type for a string More...
using | boolean_t = BooleanType
| a type for a boolean More...
using | number_integer_t = NumberIntegerType
| a type for a number (integer) More...
using | number_unsigned_t = NumberUnsignedType
| a type for a number (unsigned) More...
using | number_float_t = NumberFloatType
| a type for a number (floating-point) More...
using | binary_t = nlohmann::byte_container_with_subtype< BinaryType >
| a type for a packed binary type More...

## constructors and destructors
Constructors of class basic_json, copy/move constructor, copy assignment, static functions creating objects, and the destructor.
static basic_json | binary (const typename binary_t::container_type &init)
| explicitly create a binary array (without subtype) More...
static basic_json | binary (const typename binary_t::container_type &init, std::uint8_t subtype)
| explicitly create a binary array (with subtype) More...
static basic_json | binary (typename binary_t::container_type &&init)
| explicitly create a binary array (without subtype) More...
static basic_json | binary (typename binary_t::container_type &&init, std::uint8_t subtype)
| explicitly create a binary array (with subtype) More...
static basic_json | array (initializer_list_t init={})
| explicitly create an array from an initializer list More...
static basic_json | object (initializer_list_t init={})
| explicitly create an object from an initializer list More...
| basic_json (const value_t v)
| create an empty value with a given type More...
| basic_json (std::nullptr_t=nullptr) noexcept
| create a null object More...
template<typename CompatibleType , typename U = detail::uncvref_t<CompatibleType>, detail::enable_if_t< !detail::is_basic_json< U >::value &&detail::is_compatible_type< basic_json_t, U >::value, int > = 0>
| basic_json (CompatibleType &&val) noexcept(noexcept(JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
| create a JSON value More...
template<typename BasicJsonType , detail::enable_if_t< detail::is_basic_json< BasicJsonType >::value &&!std::is_same< basic_json, BasicJsonType >::value, int > = 0>
| basic_json (const BasicJsonType &val)
| create a JSON value from an existing one More...
| basic_json (initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
| create a container (array or object) from an initializer list More...
| basic_json (size_type cnt, const basic_json &val)
| construct an array with count copies of given value More...
template<class InputIT , typename std::enable_if< std::is_same< InputIT, typename basic_json_t::iterator >::value||std::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 More...
template<typename JsonRef , detail::enable_if_t< detail::conjunction< detail::is_json_ref< JsonRef >, std::is_same< typename JsonRef::value_type, basic_json >>::value, int > = 0>
| basic_json (const JsonRef &ref)
| basic_json (const basic_json &other)
| copy constructor More...
| basic_json (basic_json &&other) noexcept
| move constructor More...
basic_json & | operator= (basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
| copy assignment More...
| ~basic_json () noexcept
| destructor More...

## object inspection
Functions to inspect the type of a JSON value.
string_t | dump (const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
| serialization More...
constexpr value_t | type () const noexcept
| return the type of the JSON value (explicit) More...
constexpr bool | is_primitive () const noexcept
| return whether type is primitive More...
constexpr bool | is_structured () const noexcept
| return whether type is structured More...
constexpr bool | is_null () const noexcept
| return whether value is null More...
constexpr bool | is_boolean () const noexcept
| return whether value is a boolean More...
constexpr bool | is_number () const noexcept
| return whether value is a number More...
constexpr bool | is_number_integer () const noexcept
| return whether value is an integer number More...
constexpr bool | is_number_unsigned () const noexcept
| return whether value is an unsigned integer number More...
constexpr bool | is_number_float () const noexcept
| return whether value is a floating-point number More...
constexpr bool | is_object () const noexcept
| return whether value is an object More...
constexpr bool | is_array () const noexcept
| return whether value is an array More...
constexpr bool | is_string () const noexcept
| return whether value is a string More...
constexpr bool | is_binary () const noexcept
| return whether value is a binary array More...
constexpr bool | is_discarded () const noexcept
| return whether value is discarded More...
constexpr | operator value_t () const noexcept
| return the type of the JSON value (implicit) More...

## value access
Direct access to the stored value of a JSON value.
template<typename BasicJsonType , detail::enable_if_t< std::is_same< typename std::remove_const< BasicJsonType >::type, basic_json_t >::value, int > = 0>
basic_json | get () const
| get special-case overload More...
template<typename BasicJsonType , detail::enable_if_t< !std::is_same< BasicJsonType, basic_json >::value &&detail::is_basic_json< BasicJsonType >::value, int > = 0>
BasicJsonType | get () const
| get special-case overload More...
template<typename ValueTypeCV , typename ValueType = detail::uncvref_t<ValueTypeCV>, detail::enable_if_t< !detail::is_basic_json< ValueType >::value &&detail::has_from_json< basic_json_t, ValueType >::value &&!detail::has_non_default_from_json< basic_json_t, ValueType >::value, int > = 0>
ValueType | get () const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), std::declval< ValueType & >())))
| get a value (explicit) More...
template<typename ValueTypeCV , typename ValueType = detail::uncvref_t<ValueTypeCV>, detail::enable_if_t< !std::is_same< basic_json_t, ValueType >::value &&detail::has_non_default_from_json< basic_json_t, ValueType >::value, int > = 0>
ValueType | get () const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >())))
| get a value (explicit); special case More...
template<typename ValueType , detail::enable_if_t< !detail::is_basic_json< ValueType >::value &&detail::has_from_json< basic_json_t, ValueType >::value, int > = 0>
ValueType & | get_to (ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
| get a value (explicit) More...
template<typename ValueType , detail::enable_if_t< detail::is_basic_json< ValueType >::value, int > = 0>
ValueType & | get_to (ValueType &v) const
template<typename T , std::size_t N, typename Array = T (&)[N], detail::enable_if_t< detail::has_from_json< basic_json_t, Array >::value, int > = 0>
Array | get_to (T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
auto | get_ptr () noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
| get a pointer value (implicit) More...
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value &&std::is_const< typename std::remove_pointer< PointerType >::type >::value, int >::type = 0>
constexpr auto | get_ptr () const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
| get a pointer value (implicit) More...
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
auto | get () noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
| get a pointer value (explicit) More...
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
constexpr auto | get () const noexcept -> decltype(std::declval< const basic_json_t & >().template get_ptr< PointerType >())
| get a pointer value (explicit) More...
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value, int >::type = 0>
ReferenceType | get_ref ()
| get a reference value (implicit) More...
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value &&std::is_const< typename std::remove_reference< ReferenceType >::type >::value, int >::type = 0>
ReferenceType | get_ref () const
| get a reference value (implicit) More...
template<typename ValueType , typename std::enable_if< !std::is_pointer< ValueType >::value &&!std::is_same< ValueType, detail::json_ref< basic_json >>::value &&!std::is_same< ValueType, typename string_t::value_type >::value &&!detail::is_basic_json< ValueType >::value &&!std::is_same< ValueType, std::initializer_list< typename string_t::value_type >>::value &&detail::is_detected< detail::get_template_function, const basic_json_t &, ValueType >::value, int >::type = 0>
JSON_EXPLICIT | operator ValueType () const
| get a value (implicit) More...
binary_t & | get_binary ()
const binary_t & | get_binary () const

## element access
Access to the JSON value.
reference | at (size_type idx)
| access specified array element with bounds checking More...
const_reference | at (size_type idx) const
| access specified array element with bounds checking More...
reference | at (const typename object_t::key_type &key)
| access specified object element with bounds checking More...
const_reference | at (const typename object_t::key_type &key) const
| access specified object element with bounds checking More...
reference | operator[] (size_type idx)
| access specified array element More...
const_reference | operator[] (size_type idx) const
| access specified array element More...
reference | operator[] (const typename object_t::key_type &key)
| access specified object element More...
const_reference | operator[] (const typename object_t::key_type &key) const
| read-only access specified object element More...
template<typename T >
reference | operator[] (T *key)
| access specified object element More...
template<typename T >
const_reference | operator[] (T *key) const
| read-only access specified object element More...
template<class ValueType , typename std::enable_if< detail::is_getable< basic_json_t, ValueType >::value &&!std::is_same< value_t, ValueType >::value, int >::type = 0>
ValueType | value (const typename object_t::key_type &key, const ValueType &default_value) const
| access specified object element with default value More...
string_t | value (const typename object_t::key_type &key, const char *default_value) const
| overload for a default value of type const char* More...
template<class ValueType , typename std::enable_if< detail::is_getable< basic_json_t, ValueType >::value, int >::type = 0>
ValueType | value (const json_pointer &ptr, const ValueType &default_value) const
| access specified object element via JSON Pointer with default value More...
string_t | value (const json_pointer &ptr, const char *default_value) const
| overload for a default value of type const char* More...
reference | front ()
| access the first element More...
const_reference | front () const
| access the first element More...
reference | back ()
| access the last element More...
const_reference | back () const
| access the last element More...
template<class IteratorType , typename std::enable_if< std::is_same< IteratorType, typename basic_json_t::iterator >::value||std::is_same< IteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0>
IteratorType | erase (IteratorType pos)
| remove element given an iterator More...
template<class IteratorType , typename std::enable_if< std::is_same< IteratorType, typename basic_json_t::iterator >::value||std::is_same< IteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0>
IteratorType | erase (IteratorType first, IteratorType last)
| remove elements given an iterator range More...
size_type | erase (const typename object_t::key_type &key)
| remove element from a JSON object given a key More...
void | erase (const size_type idx)
| remove element from a JSON array given an index More...

## lookup
template<typename KeyT >
iterator | find (KeyT &&key)
| find an element in a JSON object More...
template<typename KeyT >
const_iterator | find (KeyT &&key) const
| find an element in a JSON object More...
template<typename KeyT >
size_type | count (KeyT &&key) const
| returns the number of occurrences of a key in a JSON object More...
template<typename KeyT , typename std::enable_if< !std::is_same< typename std::decay< KeyT >::type, json_pointer >::value, int >::type = 0>
bool | contains (KeyT &&key) const
| check the existence of an element in a JSON object More...
bool | contains (const json_pointer &ptr) const
| check the existence of an element in a JSON object given a JSON pointer More...

## iterators
static iteration_proxy< iterator > | iterator_wrapper (reference ref) noexcept
| wrapper to access iterator member functions in range-based for More...
static iteration_proxy< const_iterator > | iterator_wrapper (const_reference ref) noexcept
| wrapper to access iterator member functions in range-based for More...
iterator | begin () noexcept
| returns an iterator to the first element More...
const_iterator | begin () const noexcept
| returns a const iterator to the first element More...
const_iterator | cbegin () const noexcept
| returns a const iterator to the first element More...
iterator | end () noexcept
| returns an iterator to one past the last element More...
const_iterator | end () const noexcept
| returns a const iterator to one past the last element More...
const_iterator | cend () const noexcept
| returns a const iterator to one past the last element More...
reverse_iterator | rbegin () noexcept
| returns an iterator to the reverse-beginning More...
const_reverse_iterator | rbegin () const noexcept
| returns a const reverse iterator to the last element More...
reverse_iterator | rend () noexcept
| returns an iterator to the reverse-end More...
const_reverse_iterator | rend () const noexcept
| returns a const reverse iterator to one before the first More...
const_reverse_iterator | crbegin () const noexcept
| returns a const reverse iterator to the last element More...
const_reverse_iterator | crend () const noexcept
| returns a const reverse iterator to one before the first More...
iteration_proxy< iterator > | items () noexcept
| helper to access iterator member functions in range-based for More...
iteration_proxy< const_iterator > | items () const noexcept
| helper to access iterator member functions in range-based for More...

## capacity
bool | empty () const noexcept
| checks whether the container is empty. More...
size_type | size () const noexcept
| returns the number of elements More...
size_type | max_size () const noexcept
| returns the maximum possible number of elements More...

## modifiers
void | swap (reference left, reference right) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
| exchanges the values More...
void | clear () noexcept
| clears the contents More...
void | push_back (basic_json &&val)
| add an object to an array More...
reference | operator+= (basic_json &&val)
| add an object to an array More...
void | push_back (const basic_json &val)
| add an object to an array More...
reference | operator+= (const basic_json &val)
| add an object to an array More...
void | push_back (const typename object_t::value_type &val)
| add an object to an object More...
reference | operator+= (const typename object_t::value_type &val)
| add an object to an object More...
void | push_back (initializer_list_t init)
| add an object to an object More...
reference | operator+= (initializer_list_t init)
| add an object to an object More...
template<class... Args>
reference | emplace_back (Args &&... args)
| add an object to an array More...
template<class... Args>
std::pair< iterator, bool > | emplace (Args &&... args)
| add an object to an object if key does not exist More...
template<typename... Args>
iterator | insert_iterator (const_iterator pos, Args &&... args)
iterator | insert (const_iterator pos, const basic_json &val)
| inserts element More...
iterator | insert (const_iterator pos, basic_json &&val)
| inserts element More...
iterator | insert (const_iterator pos, size_type cnt, const basic_json &val)
| inserts elements More...
iterator | insert (const_iterator pos, const_iterator first, const_iterator last)
| inserts elements More...
iterator | insert (const_iterator pos, initializer_list_t ilist)
| inserts elements More...
void | insert (const_iterator first, const_iterator last)
| inserts elements More...
void | update (const_reference j)
| updates a JSON object from another object, overwriting existing keys More...
void | update (const_iterator first, const_iterator last)
| updates a JSON object from another object, overwriting existing keys More...
void | swap (reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
| exchanges the values More...
void | swap (array_t &other)
| exchanges the values More...
void | swap (object_t &other)
| exchanges the values More...
void | swap (string_t &other)
| exchanges the values More...
void | swap (binary_t &other)
| exchanges the values More...
void | swap (typename binary_t::container_type &other)

## lexicographical comparison operators
bool | operator== (const_reference lhs, const_reference rhs) noexcept
| comparison: equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator== (const_reference lhs, const ScalarType rhs) noexcept
| comparison: equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator== (const ScalarType lhs, const_reference rhs) noexcept
| comparison: equal More...
bool | operator!= (const_reference lhs, const_reference rhs) noexcept
| comparison: not equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator!= (const_reference lhs, const ScalarType rhs) noexcept
| comparison: not equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator!= (const ScalarType lhs, const_reference rhs) noexcept
| comparison: not equal More...
bool | operator< (const_reference lhs, const_reference rhs) noexcept
| comparison: less than More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator< (const_reference lhs, const ScalarType rhs) noexcept
| comparison: less than More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator< (const ScalarType lhs, const_reference rhs) noexcept
| comparison: less than More...
bool | operator<= (const_reference lhs, const_reference rhs) noexcept
| comparison: less than or equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator<= (const_reference lhs, const ScalarType rhs) noexcept
| comparison: less than or equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator<= (const ScalarType lhs, const_reference rhs) noexcept
| comparison: less than or equal More...
bool | operator> (const_reference lhs, const_reference rhs) noexcept
| comparison: greater than More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator> (const_reference lhs, const ScalarType rhs) noexcept
| comparison: greater than More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator> (const ScalarType lhs, const_reference rhs) noexcept
| comparison: greater than More...
bool | operator>= (const_reference lhs, const_reference rhs) noexcept
| comparison: greater than or equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator>= (const_reference lhs, const ScalarType rhs) noexcept
| comparison: greater than or equal More...
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool | operator>= (const ScalarType lhs, const_reference rhs) noexcept
| comparison: greater than or equal More...

## serialization
std::ostream & | operator<< (std::ostream &o, const basic_json &j)
| serialize to stream More...
std::ostream & | operator>> (const basic_json &j, std::ostream &o)
| serialize to stream More...

## deserialization
std::istream & | operator<< (basic_json &j, std::istream &i)
| deserialize from stream More...
std::istream & | operator>> (std::istream &i, basic_json &j)
| deserialize from stream More...
template<typename InputType >
static basic_json | parse (InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
| deserialize from a compatible input More...
template<typename IteratorType >
static basic_json | parse (IteratorType first, IteratorType last, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
| deserialize from a pair of character iterators More...
static basic_json | parse (detail::span_input_adapter &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
template<typename InputType >
static bool | accept (InputType &&i, const bool ignore_comments=false)
| check if the input is valid JSON More...
template<typename IteratorType >
static bool | accept (IteratorType first, IteratorType last, const bool ignore_comments=false)
static bool | accept (detail::span_input_adapter &&i, const bool ignore_comments=false)
template<typename InputType , typename SAX >
static bool | sax_parse (InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
| generate SAX events More...
template<class IteratorType , class SAX >
static bool | sax_parse (IteratorType first, IteratorType last, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
template<typename SAX >
static bool | sax_parse (detail::span_input_adapter &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)

## binary serialization/deserialization support
static std::vector< uint8_t > | to_cbor (const basic_json &j)
| create a CBOR serialization of a given JSON value More...
static void | to_cbor (const basic_json &j, detail::output_adapter< uint8_t > o)
static void | to_cbor (const basic_json &j, detail::output_adapter< char > o)
static std::vector< uint8_t > | to_msgpack (const basic_json &j)
| create a MessagePack serialization of a given JSON value More...
static void | to_msgpack (const basic_json &j, detail::output_adapter< uint8_t > o)
static void | to_msgpack (const basic_json &j, detail::output_adapter< char > o)
static std::vector< uint8_t > | to_ubjson (const basic_json &j, const bool use_size=false, const bool use_type=false)
| create a UBJSON serialization of a given JSON value More...
static void | to_ubjson (const basic_json &j, detail::output_adapter< uint8_t > o, const bool use_size=false, const bool use_type=false)
static void | to_ubjson (const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
static std::vector< uint8_t > | to_bson (const basic_json &j)
| Serializes the given JSON object `j` to BSON and returns a vector containing the corresponding BSON-representation. More...
static void | to_bson (const basic_json &j, detail::output_adapter< uint8_t > o)
| Serializes the given JSON object `j` to BSON and forwards the corresponding BSON-representation to the given output_adapter `o`. More...
static void | to_bson (const basic_json &j, detail::output_adapter< char > o)
| Serializes the given JSON object `j` to BSON and forwards the corresponding BSON-representation to the given output_adapter `o`. More...
template<typename InputType >
static basic_json | from_cbor (InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
| create a JSON value from an input in CBOR format More...
template<typename IteratorType >
static basic_json | from_cbor (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
template<typename T >
static basic_json | from_cbor (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
static basic_json | from_cbor (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
template<typename InputType >
static basic_json | from_msgpack (InputType &&i, const bool strict=true, const bool allow_exceptions=true)
| create a JSON value from an input in MessagePack format More...
template<typename IteratorType >
static basic_json | from_msgpack (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
template<typename T >
static basic_json | from_msgpack (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true)
static basic_json | from_msgpack (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
template<typename InputType >
static basic_json | from_ubjson (InputType &&i, const bool strict=true, const bool allow_exceptions=true)
| create a JSON value from an input in UBJSON format More...
template<typename IteratorType >
static basic_json | from_ubjson (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
template<typename T >
static basic_json | from_ubjson (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true)
static basic_json | from_ubjson (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
template<typename InputType >
static basic_json | from_bson (InputType &&i, const bool strict=true, const bool allow_exceptions=true)
| Create a JSON value from an input in BSON format. More...
template<typename IteratorType >
static basic_json | from_bson (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
template<typename T >
static basic_json | from_bson (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true)
static basic_json | from_bson (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)

## JSON Pointer functions
reference | operator[] (const json_pointer &ptr)
| access specified element via JSON Pointer More...
const_reference | operator[] (const json_pointer &ptr) const
| access specified element via JSON Pointer More...
reference | at (const json_pointer &ptr)
| access specified element via JSON Pointer More...
const_reference | at (const json_pointer &ptr) const
| access specified element via JSON Pointer More...
basic_json | flatten () const
| return flattened JSON value More...
basic_json | unflatten () const
| unflatten a previously flattened JSON value More...

## JSON Patch functions
static basic_json | diff (const basic_json &source, const basic_json &target, const std::string &path="")
| creates a diff as a JSON patch More...
basic_json | patch (const basic_json &json_patch) const
| applies a JSON patch More...

## JSON Merge Patch functions
void | merge_patch (const basic_json &apply_patch)
| applies a JSON Merge Patch More...

## Detailed Description

Template Parameters

  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)
  BinaryType | type for packed binary data for compatibility with binary serialization formats (`std::vector<std::uint8_t>` by default; will be used in binary_t)
  AllocatorType | type of the allocator to use (`std::allocator` by default)
  JSONSerializer | the serializer to resolve internal calls to `to_json()` and `from_json()` (adl_serializer by default)

Requirements
  The class satisfies the following concept requirements:
  - Basic
    - DefaultConstructible: JSON values can be default constructed. The result will be a JSON null value.
    - MoveConstructible: A JSON value can be constructed from an rvalue argument.
    - CopyConstructible: A JSON value can be copy-constructed from an lvalue expression.
    - MoveAssignable: A JSON value van be assigned from an rvalue argument.
    - CopyAssignable: A JSON value can be copy-assigned from an lvalue expression.
    - Destructible: JSON values can be destructed.
  - Layout
    - StandardLayoutType: JSON values have standard layout: All non-static data members are private and standard layout types, the class has no virtual functions or (virtual) base classes.
  - Library-wide
    - EqualityComparable: JSON values can be compared with `==`, see operator==(const_reference,const_reference).
    - LessThanComparable: JSON values can be compared with `<`, see operator<(const_reference,const_reference).
    - Swappable: Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of other compatible types, using unqualified function call swap().
    - NullablePointer: JSON values can be compared against `std::nullptr_t` objects which are used to model the `null` value.
  - Container
    - Container: JSON values can be used like STL containers and provide iterator access.
    - ReversibleContainer; JSON values can be used like STL containers and provide reverse iterator access.

Invariant
  The member variables m_value and 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().

See also
  RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format

Since
  version 1.0.0

Definition at line 16557 of file json.hpp.