MUQ  0.4.3
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > Class Template Reference

a class to store JSON values More...

#include <json.h>

Detailed Description

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

a class to store JSON values

Template Parameters
ObjectTypetype for JSON objects (std::map by default; will be used in object_t)
ArrayTypetype for JSON arrays (std::vector by default; will be used in array_t)
StringTypetype for JSON strings and object keys (std::string by default; will be used in string_t)
BooleanTypetype for JSON booleans (bool by default; will be used in boolean_t)
NumberIntegerTypetype for JSON integer numbers (int64_t by default; will be used in number_integer_t)
NumberUnsignedTypetype for JSON unsigned integer numbers (uint64_t by default; will be used in number_unsigned_t)
NumberFloatTypetype for JSON floating-point numbers (double by default; will be used in number_float_t)
BinaryTypetype for packed binary data for compatibility with binary serialization formats (std::vector<std::uint8_t> by default; will be used in binary_t)
AllocatorTypetype of the allocator to use (std::allocator by default)
JSONSerializerthe serializer to resolve internal calls to to_json() and from_json() (adl_serializer by default)

@requirement The class satisfies the following concept requirements:

Invariant
The member variables m_value and m_type have the following relationship:
See also
RFC 7159: The JavaScript Object Notation (JSON) Data Interchange Format
Since
version 1.0.0

Definition at line 16657 of file json.h.

Classes

union  json_value
 a JSON value More...
 

Public Types

using value_t = detail::value_t
 
using json_pointer = ::nlohmann::json_pointer< basic_json >
 JSON Pointer, see nlohmann::json_pointer. More...
 
template<typename T , typename SFINAE >
using json_serializer = JSONSerializer< T, SFINAE >
 
using error_handler_t = detail::error_handler_t
 how to treat decoding errors More...
 
using cbor_tag_handler_t = detail::cbor_tag_handler_t
 how to treat CBOR tags 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_sax_t = json_sax< basic_json >
 SAX interface type, see nlohmann::json_sax. More...
 
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...
 

Static Public Member Functions

static allocator_type get_allocator ()
 returns the allocator associated with the container More...
 
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta ()
 returns version information on the library More...
 

Public Attributes

SAX input_format_t const bool const bool class SAX IteratorType SAX input_format_t const bool const bool ignore_comments
 
json_value m_value = {}
 the value of the current element More...
 

Friends

template<detail::value_t >
struct detail::external_constructor
 
template<typename BasicJsonType , typename InputType >
class ::nlohmann::detail::parser
 
template<typename BasicJsonType >
class ::nlohmann::detail::iter_impl
 
template<typename BasicJsonType , typename CharType >
class ::nlohmann::detail::binary_writer
 
template<typename BasicJsonType , typename InputType , typename SAX >
class ::nlohmann::detail::binary_reader
 
template<typename BasicJsonType >
class ::nlohmann::detail::json_sax_dom_parser
 
template<typename BasicJsonType >
class ::nlohmann::detail::json_sax_dom_callback_parser
 

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<>
 
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...
 

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...
 
 JSON_HEDLEY_DEPRECATED_FOR (3.0.0, operator<<(std::ostream &, const basic_json &)) friend std
 serialize to stream More...
 

element access

Access to the JSON value.

const char *default_value const
 
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 >
 JSON_HEDLEY_NON_NULL (2) reference operator[](T *key)
 access specified object element More...
 
template<typename T >
 JSON_HEDLEY_NON_NULL (2) 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...
 
 JSON_HEDLEY_NON_NULL (3) string_t value(const json_pointer &ptr
 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...
 

deserialization

SAX * sax
 
SAX input_format_t format = input_format_t::json
 
SAX input_format_t const bool strict = true
 
SAX input_format_t const bool const bool ignore_comments
 
SAX input_format_t const bool const bool class SAX IteratorType last
 
SAX input_format_t const bool const bool class SAX IteratorType SAX * sax
 
SAX input_format_t const bool const bool class SAX IteratorType SAX input_format_t format = input_format_t::json
 
SAX input_format_t const bool const bool class SAX IteratorType SAX input_format_t const bool strict = true
 
template<typename InputType >
static JSON_HEDLEY_WARN_UNUSED_RESULT 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 JSON_HEDLEY_WARN_UNUSED_RESULT 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...
 
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)
 
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR (3.8.0, parse(ptr, ptr+len)) static basic_json parse(detail
 
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR (3.8.0, accept(ptr, ptr+len)) static bool accept(detail
 
template<typename InputType , typename SAX >
 JSON_HEDLEY_NON_NULL (2) static bool sax_parse(InputType &&i
 generate SAX events More...
 
SAX input_format_t const bool const bool class SAX JSON_HEDLEY_NON_NULL (3) static bool sax_parse(IteratorType first
 

binary serialization/deserialization support

JSON_HEDLEY_WARN_UNUSED_RESULT std::size_t len
 
JSON_HEDLEY_WARN_UNUSED_RESULT std::size_t const bool strict = true
 
JSON_HEDLEY_WARN_UNUSED_RESULT std::size_t const bool const bool allow_exceptions = true
 
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 JSON_HEDLEY_WARN_UNUSED_RESULT 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 JSON_HEDLEY_WARN_UNUSED_RESULT 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 >
JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR (3.8.0, from_cbor(ptr, ptr+len)) static basic_json from_cbor(const T *ptr
 

constructors and destructors

Constructors of class basic_json, copy/move constructor, copy assignment, static functions creating objects, and the destructor.

static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary (const typename binary_t::container_type &init)
 explicitly create a binary array (without subtype) More...
 
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary (const typename binary_t::container_type &init, std::uint8_t subtype)
 explicitly create a binary array (with subtype) More...
 
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary (typename binary_t::container_type &&init)
 explicitly create a binary array (without subtype) More...
 
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary (typename binary_t::container_type &&init, std::uint8_t subtype)
 explicitly create a binary array (with subtype) More...
 
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array (initializer_list_t init={})
 explicitly create an array from an initializer list More...
 
static JSON_HEDLEY_WARN_UNUSED_RESULT 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_jsonoperator= (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#if defined(JSON_HAS_CPP_17) &&(defined(__GNUC__)||(defined(_MSC_VER) &&_MSC_VER >=1910 &&_MSC_VER<=1914)) &&!std::is_same< ValueType, typename std::string_view >::value#endif &&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_tget_binary ()
 
const binary_tget_binary () const
 

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

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...
 
 JSON_HEDLEY_DEPRECATED_FOR (3.1.0, items()) static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
 wrapper to access iterator member functions in range-based for More...
 
 JSON_HEDLEY_DEPRECATED_FOR (3.1.0, items()) static iteration_proxy< const_iterator > iterator_wrapper(const_reference ref) noexcept
 
iteration_proxy< iteratoritems () noexcept
 helper to access iterator member functions in range-based for More...
 
iteration_proxy< const_iteratoritems () 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...
 

Member Typedef Documentation

◆ allocator_type

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::allocator_type = AllocatorType<basic_json>

the allocator type

Definition at line 16777 of file json.h.

◆ array_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::array_t = ArrayType<basic_json, AllocatorType<basic_json> >

a type for an array

RFC 7159 describes JSON arrays as follows:

An array is an ordered sequence of zero or more values.

To store objects in C++, a type is defined by the template parameters explained below.

Template Parameters
ArrayTypecontainer type to store arrays (e.g., std::vector or std::list)
AllocatorTypeallocator to use for arrays (e.g., std::allocator)

Default type

With the default values for ArrayType (std::vector) and AllocatorType (std::allocator), the default value for array_t is:

std::vector<
basic_json, // value_type
std::allocator<basic_json> // allocator_type
>
basic_json(const value_t v)
create an empty value with a given type
Definition: json.h:17830

Limits

RFC 7159 specifies:

An implementation may set limits on the maximum depth of nesting.

In this class, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the max_size function of a JSON array.

Storage

Arrays are stored as pointers in a basic_json type. That is, for any access to array values, a pointer of type array_t* must be dereferenced.

See also
object_ttype for an object value
Since
version 1.0.0

Definition at line 17037 of file json.h.

◆ basic_json_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json_t = NLOHMANN_BASIC_JSON_TPL
private

workaround type for MSVC

Definition at line 16678 of file json.h.

◆ binary_reader

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>
private

Definition at line 16708 of file json.h.

◆ binary_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary_t = nlohmann::byte_container_with_subtype<BinaryType>

a type for a packed binary type

This type is a type designed to carry binary data that appears in various serialized formats, such as CBOR's Major Type 2, MessagePack's bin, and BSON's generic binary subtype. This type is NOT a part of standard JSON and exists solely for compatibility with these binary types. As such, it is simply defined as an ordered sequence of zero or more byte values.

Additionally, as an implementation detail, the subtype of the binary data is carried around as a std::uint8_t, which is compatible with both of the binary data formats that use binary subtyping, (though the specific numbering is incompatible with each other, and it is up to the user to translate between them).

CBOR's RFC 7049 describes this type as:

Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers (major type 0).

MessagePack's documentation on the bin type family describes this type as:

Bin format family stores an byte array in 2, 3, or 5 bytes of extra bytes in addition to the size of the byte array.

BSON's specifications describe several binary types; however, this type is intended to represent the generic binary type which has the description:

Generic binary subtype - This is the most commonly used binary subtype and should be the 'default' for drivers and tools.

None of these impose any limitations on the internal representation other than the basic unit of storage be some type of array whose parts are decomposable into bytes.

The default representation of this binary format is a std::vector<std::uint8_t>, which is a very common way to represent a byte array in modern C++.

Default type

The default values for BinaryType is std::vector<std::uint8_t>

Storage

Binary Arrays are stored as pointers in a basic_json type. That is, for any access to array values, a pointer of the type binary_t* must be dereferenced.

Notes on subtypes

  • CBOR
    • Binary values are represented as byte strings. No subtypes are supported and will be ignored when CBOR is written.
  • MessagePack
    • If a subtype is given and the binary array contains exactly 1, 2, 4, 8, or 16 elements, the fixext family (fixext1, fixext2, fixext4, fixext8) is used. For other sizes, the ext family (ext8, ext16, ext32) is used. The subtype is then added as singed 8-bit integer.
    • If no subtype is given, the bin family (bin8, bin16, bin32) is used.
  • BSON
    • If a subtype is given, it is used and added as unsigned 8-bit integer.
    • If no subtype is given, the generic binary subtype 0x00 is used.
See also
binarycreate a binary array
Since
version 3.8.0

Definition at line 17398 of file json.h.

◆ binary_writer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename CharType >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>
private

Definition at line 16709 of file json.h.

◆ boolean_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::boolean_t = BooleanType

a type for a boolean

RFC 7159 implicitly describes a boolean as a type which differentiates the two literals true and false.

To store objects in C++, a type is defined by the template parameter BooleanType which chooses the type to use.

Default type

With the default values for BooleanType (bool), the default value for boolean_t is:

bool

Storage

Boolean values are stored directly inside a basic_json type.

Since
version 1.0.0

Definition at line 17116 of file json.h.

◆ cbor_tag_handler_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cbor_tag_handler_t = detail::cbor_tag_handler_t

how to treat CBOR tags

Definition at line 16722 of file json.h.

◆ const_iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::const_iterator = iter_impl<const basic_json>

a const iterator for a basic_json container

Definition at line 16787 of file json.h.

◆ const_pointer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::const_pointer = typename std::allocator_traits<allocator_type>::const_pointer

the type of an element const pointer

Definition at line 16782 of file json.h.

◆ const_reference

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::const_reference = const value_type&

the type of an element const reference

Definition at line 16769 of file json.h.

◆ const_reverse_iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::const_reverse_iterator = json_reverse_iterator<typename basic_json::const_iterator>

a const reverse iterator for a basic_json container

Definition at line 16791 of file json.h.

◆ difference_type

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::difference_type = std::ptrdiff_t

a type to represent differences between iterators

Definition at line 16772 of file json.h.

◆ error_handler_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::error_handler_t = detail::error_handler_t

how to treat decoding errors

Definition at line 16720 of file json.h.

◆ exception

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::exception = detail::exception

general exception of the basic_json class

This class is an extension of std::exception objects with a member id for exception ids. It is used as the base class for all exceptions thrown by the basic_json class. This class can hence be used as "wildcard" to catch exceptions.

Subclasses:

  • parse_error for exceptions indicating a parse error
  • invalid_iterator for exceptions indicating errors with iterators
  • type_error for exceptions indicating executing a member function with a wrong type
  • out_of_range for exceptions indicating access out of the defined range
  • other_error for exceptions indicating other library errors

@liveexample{The following code shows how arbitrary library exceptions can be caught.,exception}

Since
version 3.0.0

Definition at line 16739 of file json.h.

◆ initializer_list_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::initializer_list_t = std::initializer_list<detail::json_ref<basic_json> >

helper type for initializer lists of basic_json values

Definition at line 16724 of file json.h.

◆ input_format_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::input_format_t = detail::input_format_t

Definition at line 16726 of file json.h.

◆ internal_iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>
private

Definition at line 16697 of file json.h.

◆ invalid_iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::invalid_iterator = detail::invalid_iterator

exception indicating errors with iterators

This exception is thrown if iterators passed to a library function do not match the expected semantics.

Exceptions have ids 2xx.

name / id example message description
json.exception.invalid_iterator.201 iterators are not compatible The iterators passed to constructor basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (first, last) is invalid.
json.exception.invalid_iterator.202 iterator does not fit current value In an erase or insert function, the passed iterator pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion.
json.exception.invalid_iterator.203 iterators do not fit current value Either iterator passed to function erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from.
json.exception.invalid_iterator.204 iterators out of range When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (begin(), end()), because this is the only way the single stored value is expressed. All other ranges are invalid.
json.exception.invalid_iterator.205 iterator out of range When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the begin() iterator, because it is the only way to address the stored value. All other iterators are invalid.
json.exception.invalid_iterator.206 cannot construct with iterators from null The iterators passed to constructor basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range.
json.exception.invalid_iterator.207 cannot use key() for non-object iterators The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key.
json.exception.invalid_iterator.208 cannot use operator[] for object iterators The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.209 cannot use offsets with object iterators The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered.
json.exception.invalid_iterator.210 iterators do not fit The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (first, last) is invalid.
json.exception.invalid_iterator.211 passed iterators may not belong to container The iterator range passed to the insert function must not be a subrange of the container to insert to.
json.exception.invalid_iterator.212 cannot compare iterators of different containers When two iterators are compared, they must belong to the same container.
json.exception.invalid_iterator.213 cannot compare order of object iterators The order of object iterators cannot be compared, because JSON objects are unordered.
json.exception.invalid_iterator.214 cannot get value Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to begin().

@liveexample{The following code shows how an invalid_iterator exception can be caught.,invalid_iterator}

See also
- exception for the base class of the library exceptions
- parse_error for exceptions indicating a parse error
- type_error for exceptions indicating executing a member function with a wrong type
- out_of_range for exceptions indicating access out of the defined range
- other_error for exceptions indicating other library errors
Since
version 3.0.0

Definition at line 16743 of file json.h.

◆ iter_impl

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>
private

Definition at line 16699 of file json.h.

◆ iteration_proxy

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename Iterator >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>
private

Definition at line 16701 of file json.h.

◆ iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::iterator = iter_impl<basic_json>

an iterator for a basic_json container

Definition at line 16785 of file json.h.

◆ json_pointer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_pointer = ::nlohmann::json_pointer<basic_json>

JSON Pointer, see nlohmann::json_pointer.

Definition at line 16716 of file json.h.

◆ json_reverse_iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename Base >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>
private

Definition at line 16702 of file json.h.

◆ json_sax_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_sax_t = json_sax<basic_json>

SAX interface type, see nlohmann::json_sax.

Definition at line 16728 of file json.h.

◆ json_serializer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename T , typename SFINAE >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_serializer = JSONSerializer<T, SFINAE>

Definition at line 16718 of file json.h.

◆ lexer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::lexer = ::nlohmann::detail::lexer_base<basic_json>
private

Definition at line 16681 of file json.h.

◆ number_float_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::number_float_t = NumberFloatType

a type for a number (floating-point)

RFC 7159 describes numbers as follows:

The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed. (...) Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

This description includes both integer and floating-point numbers. However, C++ allows more precise storage if it is known whether the number is a signed integer, an unsigned integer or a floating-point number. Therefore, three different types, number_integer_t, number_unsigned_t and number_float_t are used.

To store floating-point numbers in C++, a type is defined by the template parameter NumberFloatType which chooses the type to use.

Default type

With the default values for NumberFloatType (double), the default value for number_float_t is:

double

Default behavior

  • The restrictions about leading zeros is not enforced in C++. Instead, leading zeros in floating-point literals will be ignored. Internally, the value will be stored as decimal number. For instance, the C++ floating-point literal 01.2 will be serialized to 1.2. During deserialization, leading zeros yield an error.
  • Not-a-number (NaN) values will be serialized to null.

Limits

RFC 7159 states:

This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754-2008 binary64 (double precision) numbers is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision.

This implementation does exactly follow this approach, as it uses double precision floating-point numbers. Note values smaller than -1.79769313486232e+308 and values greater than 1.79769313486232e+308 will be stored as NaN internally and be serialized to null.

Storage

Floating-point number values are stored directly inside a basic_json type.

See also
number_integer_ttype for number values (integer)
number_unsigned_ttype for number values (unsigned integer)
Since
version 1.0.0

Definition at line 17327 of file json.h.

◆ number_integer_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::number_integer_t = NumberIntegerType

a type for a number (integer)

RFC 7159 describes numbers as follows:

The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed. (...) Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

This description includes both integer and floating-point numbers. However, C++ allows more precise storage if it is known whether the number is a signed integer, an unsigned integer or a floating-point number. Therefore, three different types, number_integer_t, number_unsigned_t and number_float_t are used.

To store integer numbers in C++, a type is defined by the template parameter NumberIntegerType which chooses the type to use.

Default type

With the default values for NumberIntegerType (int64_t), the default value for number_integer_t is:

int64_t

Default behavior

  • The restrictions about leading zeros is not enforced in C++. Instead, leading zeros in integer literals lead to an interpretation as octal number. Internally, the value will be stored as decimal number. For instance, the C++ integer literal 010 will be serialized to 8. During deserialization, leading zeros yield an error.
  • Not-a-number (NaN) values will be serialized to null.

Limits

RFC 7159 specifies:

An implementation may set limits on the range and precision of numbers.

When the default type is used, the maximal integer number that can be stored is 9223372036854775807 (INT64_MAX) and the minimal integer number that can be stored is -9223372036854775808 (INT64_MIN). Integer numbers that are out of range will yield over/underflow when used in a constructor. During deserialization, too large or small integer numbers will be automatically be stored as number_unsigned_t or number_float_t.

RFC 7159 further states:

Note that when such software is used, numbers that are integers and are in the range \([-2^{53}+1, 2^{53}-1]\) are interoperable in the sense that implementations will agree exactly on their numeric values.

As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is interoperable.

Storage

Integer number values are stored directly inside a basic_json type.

See also
number_float_ttype for number values (floating-point)
number_unsigned_ttype for number values (unsigned integer)
Since
version 1.0.0

Definition at line 17188 of file json.h.

◆ number_unsigned_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::number_unsigned_t = NumberUnsignedType

a type for a number (unsigned)

RFC 7159 describes numbers as follows:

The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed. (...) Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

This description includes both integer and floating-point numbers. However, C++ allows more precise storage if it is known whether the number is a signed integer, an unsigned integer or a floating-point number. Therefore, three different types, number_integer_t, number_unsigned_t and number_float_t are used.

To store unsigned integer numbers in C++, a type is defined by the template parameter NumberUnsignedType which chooses the type to use.

Default type

With the default values for NumberUnsignedType (uint64_t), the default value for number_unsigned_t is:

uint64_t

Default behavior

  • The restrictions about leading zeros is not enforced in C++. Instead, leading zeros in integer literals lead to an interpretation as octal number. Internally, the value will be stored as decimal number. For instance, the C++ integer literal 010 will be serialized to 8. During deserialization, leading zeros yield an error.
  • Not-a-number (NaN) values will be serialized to null.

Limits

RFC 7159 specifies:

An implementation may set limits on the range and precision of numbers.

When the default type is used, the maximal integer number that can be stored is 18446744073709551615 (UINT64_MAX) and the minimal integer number that can be stored is 0. Integer numbers that are out of range will yield over/underflow when used in a constructor. During deserialization, too large or small integer numbers will be automatically be stored as number_integer_t or number_float_t.

RFC 7159 further states:

Note that when such software is used, numbers that are integers and are in the range \([-2^{53}+1, 2^{53}-1]\) are interoperable in the sense that implementations will agree exactly on their numeric values.

As this range is a subrange (when considered in conjunction with the number_integer_t type) of the exactly supported range [0, UINT64_MAX], this class's integer type is interoperable.

Storage

Integer number values are stored directly inside a basic_json type.

See also
number_float_ttype for number values (floating-point)
number_integer_ttype for number values (integer)
Since
version 2.0.0

Definition at line 17259 of file json.h.

◆ object_comparator_t [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::object_comparator_t = std::less<>

Definition at line 16899 of file json.h.

◆ object_comparator_t [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::object_comparator_t = std::less<StringType>

Definition at line 16901 of file json.h.

◆ object_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::object_t = ObjectType<StringType, basic_json, object_comparator_t, AllocatorType<std::pair<const StringType, basic_json> >>

a type for an object

RFC 7159 describes JSON objects as follows:

An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.

To store objects in C++, a type is defined by the template parameters described below.

Template Parameters
ObjectTypethe container to store objects (e.g., std::map or std::unordered_map)
StringTypethe type of the keys or names (e.g., std::string). The comparison function std::less<StringType> is used to order elements inside the container.
AllocatorTypethe allocator to use for objects (e.g., std::allocator)

Default type

With the default values for ObjectType (std::map), StringType (std::string), and AllocatorType (std::allocator), the default value for object_t is:

std::map<
std::string, // key_type
basic_json, // value_type
std::less<std::string>, // key_compare
std::allocator<std::pair<const std::string, basic_json>> // allocator_type
>

Behavior

The choice of object_t influences the behavior of the JSON class. With the default type, objects have the following behavior:

  • When all names are unique, objects will be interoperable in the sense that all software implementations receiving that object will agree on the name-value mappings.
  • When the names within an object are not unique, it is unspecified which one of the values for a given key will be chosen. For instance, {"key": 2, "key": 1} could be equal to either {"key": 1} or {"key": 2}.
  • Internally, name/value pairs are stored in lexicographical order of the names. Objects will also be serialized (see dump) in this order. For instance, {"b": 1, "a": 2} and {"a": 2, "b": 1} will be stored and serialized as {"a": 2, "b": 1}.
  • When comparing objects, the order of the name/value pairs is irrelevant. This makes objects interoperable in the sense that they will not be affected by these differences. For instance, {"b": 1, "a": 2} and {"a": 2, "b": 1} will be treated as equal.

Limits

RFC 7159 specifies:

An implementation may set limits on the maximum depth of nesting.

In this class, the object's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the max_size function of a JSON object.

Storage

Objects are stored as pointers in a basic_json type. That is, for any access to object values, a pointer of type object_t* must be dereferenced.

See also
array_ttype for an array value
Since
version 1.0.0
Note
The order name/value pairs are added to the object is not preserved by the library. Therefore, iterating an object may return name/value pairs in a different order than they were originally stored. In fact, keys will be traversed in alphabetical order as std::map with std::less is used by default. Please note this behavior conforms to RFC 7159, because any order implements the specified "unordered" nature of JSON objects.

Definition at line 16987 of file json.h.

◆ other_error

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::other_error = detail::other_error

exception indicating other library errors

This exception is thrown in case of errors that cannot be classified with the other exception types.

Exceptions have ids 5xx.

name / id example message description
json.exception.other_error.501 unsuccessful: {"op":"test","path":"/baz", "value":"bar"} A JSON Patch operation 'test' failed. The unsuccessful operation is also printed.
See also
- exception for the base class of the library exceptions
- parse_error for exceptions indicating a parse error
- invalid_iterator for exceptions indicating errors with iterators
- type_error for exceptions indicating executing a member function with a wrong type
- out_of_range for exceptions indicating access out of the defined range

@liveexample{The following code shows how an other_error exception can be caught.,other_error}

Since
version 3.0.0

Definition at line 16749 of file json.h.

◆ out_of_range

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::out_of_range = detail::out_of_range

exception indicating access out of the defined range

This exception is thrown in case a library function is called on an input parameter that exceeds the expected range, for instance in case of array indices or nonexisting object keys.

Exceptions have ids 4xx.

name / id example message description
json.exception.out_of_range.401 array index 3 is out of range The provided array index i is larger than size-1.
json.exception.out_of_range.402 array index '-' (3) is out of range The special array index - in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it.
json.exception.out_of_range.403 key 'foo' not found The provided key was not found in the JSON object.
json.exception.out_of_range.404 unresolved reference token 'foo' A reference token in a JSON Pointer could not be resolved.
json.exception.out_of_range.405 JSON pointer has no parent The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value.
json.exception.out_of_range.406 number overflow parsing '10E1000' A parsed number could not be stored as without changing it to NaN or INF.
json.exception.out_of_range.407 number overflow serializing '9223372036854775808' UBJSON and BSON only support integer numbers up to 9223372036854775807. (until version 3.8.0)
json.exception.out_of_range.408 excessive array size: 8658170730974374167 The size (following #) of an UBJSON array or object exceeds the maximal capacity.
json.exception.out_of_range.409 BSON key cannot contain code point U+0000 (at byte 2) Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string

@liveexample{The following code shows how an out_of_range exception can be caught.,out_of_range}

See also
- exception for the base class of the library exceptions
- parse_error for exceptions indicating a parse error
- invalid_iterator for exceptions indicating errors with iterators
- type_error for exceptions indicating executing a member function with a wrong type
- other_error for exceptions indicating other library errors
Since
version 3.0.0

Definition at line 16747 of file json.h.

◆ output_adapter_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename CharType >
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>
private

Definition at line 16705 of file json.h.

◆ parse_error

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parse_error = detail::parse_error

exception indicating a parse error

This exception is thrown by the library when a parse error occurs. Parse errors can occur during the deserialization of JSON text, CBOR, MessagePack, as well as when using JSON Patch.

Member byte holds the byte index of the last read character in the input file.

Exceptions have ids 1xx.

name / id example message description
json.exception.parse_error.101 parse error at 2: unexpected end of input; expected string literal This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member byte indicates the error position.
json.exception.parse_error.102 parse error at 14: missing or wrong low surrogate JSON uses the \uxxxx format to describe Unicode characters. Code points above above 0xFFFF are split into two \uxxxx entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point.
json.exception.parse_error.103 parse error: code points above 0x10FFFF are invalid Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid.
json.exception.parse_error.104 parse error: JSON patch must be an array of objects RFC 6902 requires a JSON Patch document to be a JSON document that represents an array of objects.
json.exception.parse_error.105 parse error: operation must have string member 'op' An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors.
json.exception.parse_error.106 parse error: array index '01' must not begin with '0' An array index in a JSON Pointer (RFC 6901) may be 0 or any number without a leading 0.
json.exception.parse_error.107 parse error: JSON pointer must be empty or begin with '/' - was: 'foo' A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a / character.
json.exception.parse_error.108 parse error: escape character '~' must be followed with '0' or '1' In a JSON Pointer, only ~0 and ~1 are valid escape sequences.
json.exception.parse_error.109 parse error: array index 'one' is not a number A JSON Pointer array index must be a number.
json.exception.parse_error.110 parse error at 1: cannot read 2 bytes from vector When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read.
json.exception.parse_error.112 parse error at 1: error reading CBOR; last byte: 0xF8 Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read.
json.exception.parse_error.113 parse error at 2: expected a CBOR string; last byte: 0x98 While parsing a map key, a value that is not a string has been read.
json.exception.parse_error.114 parse error: Unsupported BSON record type 0x0F The parsing of the corresponding BSON record type is not implemented (yet).
json.exception.parse_error.115 parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A A UBJSON high-precision number could not be parsed.
Note
For an input with n bytes, 1 is the index of the first character and n+1 is the index of the terminating null byte or the end of file. This also holds true when reading a byte vector (CBOR or MessagePack).

@liveexample{The following code shows how a parse_error exception can be caught.,parse_error}

See also
- exception for the base class of the library exceptions
- invalid_iterator for exceptions indicating errors with iterators
- type_error for exceptions indicating executing a member function with a wrong type
- out_of_range for exceptions indicating access out of the defined range
- other_error for exceptions indicating other library errors
Since
version 3.0.0

Definition at line 16741 of file json.h.

◆ parse_event_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parse_event_t = detail::parse_event_t

parser event types

The parser callback distinguishes the following events:

  • object_start: the parser read { and started to process a JSON object
  • key: the parser read a key of a value in an object
  • object_end: the parser read } and finished processing a JSON object
  • array_start: the parser read [ and started to process a JSON array
  • array_end: the parser read ] and finished processing a JSON array
  • value: the parser finished reading a JSON value
Example when certain parse events are triggered
See also
parser_callback_t for more information and examples

Definition at line 17738 of file json.h.

◆ parser_callback_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parser_callback_t = detail::parser_callback_t<basic_json>

per-element parser callback type

With a parser callback function, the result of parsing a JSON text can be influenced. When passed to parse, it is called on certain events (passed as parse_event_t via parameter event) with a set recursion depth depth and context JSON value parsed. The return value of the callback function is a boolean indicating whether the element that emitted the callback shall be kept or not.

We distinguish six scenarios (determined by the event type) in which the callback function can be called. The following table describes the values of the parameters depth, event, and parsed.

parameter event description parameter depth parameter parsed
parse_event_t::object_start the parser read { and started to process a JSON object depth of the parent of the JSON object a JSON value with type discarded
parse_event_t::key the parser read a key of a value in an object depth of the currently parsed JSON object a JSON string containing the key
parse_event_t::object_end the parser read } and finished processing a JSON object depth of the parent of the JSON object the parsed JSON object
parse_event_t::array_start the parser read [ and started to process a JSON array depth of the parent of the JSON array a JSON value with type discarded
parse_event_t::array_end the parser read ] and finished processing a JSON array depth of the parent of the JSON array the parsed JSON array
parse_event_t::value the parser finished reading a JSON value depth of the value the parsed JSON value
Example when certain parse events are triggered

Discarding a value (i.e., returning false) has different effects depending on the context in which function was called:

  • Discarded values in structured types are skipped. That is, the parser will behave as if the discarded value was never read.
  • In case a value outside a structured type is skipped, it is replaced with null. This case happens if the top-level element is skipped.
Parameters
[in]depththe depth of the recursion during parsing
[in]eventan event of type parse_event_t indicating the context in the callback function has been called
[in,out]parsedthe current intermediate parse result; note that writing to this value has no effect for parse_event_t::key events
Returns
Whether the JSON value which called the function during parsing should be kept (true) or not (false). In the latter case, it is either skipped completely or replaced by an empty discarded object.
See also
parse for examples
Since
version 1.0.0

Definition at line 17789 of file json.h.

◆ pointer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::pointer = typename std::allocator_traits<allocator_type>::pointer

the type of an element pointer

Definition at line 16780 of file json.h.

◆ primitive_iterator_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t
private

Definition at line 16695 of file json.h.

◆ reference

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::reference = value_type&

the type of an element reference

Definition at line 16767 of file json.h.

◆ reverse_iterator

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::reverse_iterator = json_reverse_iterator<typename basic_json::iterator>

a reverse iterator for a basic_json container

Definition at line 16789 of file json.h.

◆ serializer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::serializer = ::nlohmann::detail::serializer<basic_json>
private

Definition at line 16711 of file json.h.

◆ size_type

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::size_type = std::size_t

a type to represent container sizes

Definition at line 16774 of file json.h.

◆ string_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::string_t = StringType

a type for a string

RFC 7159 describes JSON strings as follows:

A string is a sequence of zero or more Unicode characters.

To store objects in C++, a type is defined by the template parameter described below. Unicode values are split by the JSON class into byte-sized characters during deserialization.

Template Parameters
StringTypethe container to store strings (e.g., std::string). Note this container is used for keys/names in objects, see object_t.

Default type

With the default values for StringType (std::string), the default value for string_t is:

std::string

Encoding

Strings are stored in UTF-8 encoding. Therefore, functions like std::string::size() or std::string::length() return the number of bytes in the string rather than the number of characters or glyphs.

String comparison

RFC 7159 states:

Software implementations are typically required to test names of object members for equality. Implementations that transform the textual representation into sequences of Unicode code units and then perform the comparison numerically, code unit by code unit, are interoperable in the sense that implementations will agree in all cases on equality or inequality of two strings. For example, implementations that compare strings with escaped characters unconverted may incorrectly find that "a\\b" and "a\u005Cb" are not equal.

This implementation is interoperable as it does compare strings code unit by code unit.

Storage

String values are stored as pointers in a basic_json type. That is, for any access to string values, a pointer of type string_t* must be dereferenced.

Since
version 1.0.0

Definition at line 17090 of file json.h.

◆ type_error

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::type_error = detail::type_error

exception indicating executing a member function with a wrong type

This exception is thrown in case of a type error; that is, a library function is executed on a JSON value whose type does not match the expected semantics.

Exceptions have ids 3xx.

name / id example message description
json.exception.type_error.301 cannot create object from initializer list To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead.
json.exception.type_error.302 type must be object, but is array During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types.
json.exception.type_error.303 incompatible ReferenceType for get_ref, actual type is object To retrieve a reference to a value stored in a basic_json object with get_ref, the type of the reference must match the value type. For instance, for a JSON array, the ReferenceType must be array_t &.
json.exception.type_error.304 cannot use at() with string The at() member functions can only be executed for certain JSON types.
json.exception.type_error.305 cannot use operator[] with string The operator[] member functions can only be executed for certain JSON types.
json.exception.type_error.306 cannot use value() with string The value() member functions can only be executed for certain JSON types.
json.exception.type_error.307 cannot use erase() with string The erase() member functions can only be executed for certain JSON types.
json.exception.type_error.308 cannot use push_back() with string The push_back() and operator+= member functions can only be executed for certain JSON types.
json.exception.type_error.309 cannot use insert() with The insert() member functions can only be executed for certain JSON types.
json.exception.type_error.310 cannot use swap() with number The swap() member functions can only be executed for certain JSON types.
json.exception.type_error.311 cannot use emplace_back() with string The emplace_back() member function can only be executed for certain JSON types.
json.exception.type_error.312 cannot use update() with string The update() member functions can only be executed for certain JSON types.
json.exception.type_error.313 invalid value to unflatten The unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined.
json.exception.type_error.314 only objects can be unflattened The unflatten function only works for an object whose keys are JSON Pointers.
json.exception.type_error.315 values in object must be primitive The unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive.
json.exception.type_error.316 invalid UTF-8 byte at index 10: 0x7E The dump function only works with UTF-8 encoded strings; that is, if you assign a std::string to a JSON value, make sure it is UTF-8 encoded.
json.exception.type_error.317 JSON value cannot be serialized to requested format The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw true or null JSON object cannot be serialized to BSON)

@liveexample{The following code shows how a type_error exception can be caught.,type_error}

See also
- exception for the base class of the library exceptions
- parse_error for exceptions indicating a parse error
- invalid_iterator for exceptions indicating errors with iterators
- out_of_range for exceptions indicating access out of the defined range
- other_error for exceptions indicating other library errors
Since
version 3.0.0

Definition at line 16745 of file json.h.

◆ value_t

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value_t = detail::value_t

Definition at line 16714 of file json.h.

◆ value_type

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value_type = basic_json

the type of elements in a basic_json container

Definition at line 16764 of file json.h.

Constructor & Destructor Documentation

◆ basic_json() [1/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( const value_t  v)
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 []
binary empty array
Parameters
[in]vthe type of the value to create

@complexity Constant.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The following code shows the constructor for different value_t values,basic_json__value_t}

See also
clear() – restores the postcondition of this constructor
Since
version 1.0.0

Definition at line 17830 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::from_cbor(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back().

◆ basic_json() [2/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( std::nullptr_t  = nullptr)
inlinenoexcept

create a null object

Create a null JSON value. It either takes a null pointer as parameter (explicitly creating null) or no parameter (implicitly creating null). The passed null pointer itself is not read – it is only used to choose the right constructor.

@complexity Constant.

@exceptionsafety No-throw guarantee: this constructor never throws exceptions.

@liveexample{The following code shows the constructor with and without a null pointer parameter.,basic_json__nullptr_t}

Since
version 1.0.0

Definition at line 17854 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant().

◆ basic_json() [3/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( CompatibleType &&  val)
inlinenoexcept

create a JSON value

This is a "catch all" constructor for all compatible JSON types; that is, types for which a to_json() method exists. The constructor forwards the parameter val to that method (to json_serializer<U>::to_json method with U = uncvref_t<CompatibleType>, to be exact).

Template type CompatibleType includes, but is not limited to, the following types:

  • arrays: array_t and all kinds of compatible containers such as std::vector, std::deque, std::list, std::forward_list, std::array, std::valarray, std::set, std::unordered_set, std::multiset, and std::unordered_multiset with a value_type from which a basic_json value can be constructed.
  • objects: object_t and all kinds of compatible associative containers such as std::map, std::unordered_map, std::multimap, and std::unordered_multimap with a key_type compatible to string_t and a value_type from which a basic_json value can be constructed.
  • strings: string_t, string literals, and all compatible string containers can be used.
  • numbers: number_integer_t, number_unsigned_t, number_float_t, and all convertible number types such as int, size_t, int64_t, float or double can be used.
  • boolean: boolean_t / bool can be used.
  • binary: binary_t / std::vector<uint8_t> may be used, unfortunately because string literals cannot be distinguished from binary character arrays by the C++ type system, all types compatible with const char* will be directed to the string constructor instead. This is both for backwards compatibility, and due to the fact that a binary type is not a standard JSON type.

See the examples below.

Template Parameters
CompatibleTypea type such that:
  • CompatibleType is not derived from std::istream,
  • CompatibleType is not basic_json (to avoid hijacking copy/move constructors),
  • CompatibleType is not a different basic_json type (i.e. with different template arguments)
  • CompatibleType is not a basic_json nested type (e.g., json_pointer, iterator, etc ...)
  • @ref json_serializer has a to_json(basic_json_t&, CompatibleType&&) method
U= uncvref_t<CompatibleType>
Parameters
[in]valthe value to be forwarded to the respective constructor

@complexity Usually linear in the size of the passed val, also depending on the implementation of the called to_json() method.

@exceptionsafety Depends on the called constructor. For types directly supported by the library (i.e., all types for which no to_json() function was provided), strong guarantee holds: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The following code shows the constructor with several compatible types.,basic_json__CompatibleType}

Since
version 2.1.0

Definition at line 17927 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), and nlohmann::detail::to_json().

◆ basic_json() [4/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType , detail::enable_if_t< detail::is_basic_json< BasicJsonType >::value &&!std::is_same< basic_json, BasicJsonType >::value, int > = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( const BasicJsonType &  val)
inline

create a JSON value from an existing one

This is a constructor for existing basic_json types. It does not hijack copy/move constructors, since the parameter has different template arguments than the current ones.

The constructor tries to convert the internal m_value of the parameter.

Template Parameters
BasicJsonTypea type such that:
Parameters
[in]valthe basic_json value to be converted.

@complexity Usually linear in the size of the passed val, also depending on the implementation of the called to_json() method.

@exceptionsafety Depends on the called constructor. For types directly supported by the library (i.e., all types for which no to_json() function was provided), strong guarantee holds: if an exception is thrown, there are no changes to any JSON value.

Since
version 3.2.0

Definition at line 17964 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::discarded, nlohmann::detail::JSON_ASSERT(), nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, nlohmann::detail::string, and nlohmann::detail::to_json().

◆ basic_json() [5/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( initializer_list_t  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 no 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:

Note
When used without parentheses around an empty initializer list, basic_json() is called instead of this function, yielding the JSON null value.
Parameters
[in]initinitializer list with JSON values
[in]type_deductioninternal 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(initializer_list_t) and object(initializer_list_t).
[in]manual_typeinternal 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
Exceptions
type_error.301if 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. In this case, the constructor could not create an object. If type_deduction would have be true, an array would have been created. See object(initializer_list_t) for an example.

@complexity Linear in the size of the initializer list init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The example below shows how JSON values are created from initializer lists.,basic_json__list_init_t}

See also
array(initializer_list_t)create a JSON array value from an initializer list
object(initializer_list_t)create a JSON object value from an initializer list
Since
version 1.0.0

Definition at line 18087 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::detail::object.

◆ basic_json() [6/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( size_type  cnt,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  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.

Parameters
[in]cntthe number of JSON copies of val to create
[in]valthe JSON value to copy
Postcondition
std::distance(begin(),end()) == cnt holds.

@complexity Linear in cnt.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The following code shows examples for the basic_json(size_type\, const basic_json&) constructor.,basic_json__size_type_basic_json}

Since
version 1.0.0

Definition at line 18341 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ basic_json() [7/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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:

  • In case of a null type, invalid_iterator.206 is thrown.
  • In case of other primitive types (number, boolean, or string), first must be begin() and last must be end(). In this case, the value is copied. Otherwise, invalid_iterator.204 is thrown.
  • In case of structured types (array, object), the constructor behaves as similar versions for std::vector or std::map; that is, a JSON array or object is constructed from the values in the range.
Template Parameters
InputITan input iterator type (iterator or const_iterator)
Parameters
[in]firstbegin of the range to copy from (included)
[in]lastend of the range to copy from (excluded)
Precondition
Iterators first and last must be initialized. This precondition is enforced with an assertion (see warning). If assertions are switched off, a violation of this precondition yields undefined behavior.
Range [first, last) is valid. Usually, this precondition cannot be checked efficiently. Only certain edge cases are detected; see the description of the exceptions below. A violation of this precondition yields undefined behavior.
Warning
A precondition is enforced with a runtime assertion that will result in calling std::abort if this precondition is not met. Assertions can be disabled by defining NDEBUG at compile time. See https://en.cppreference.com/w/cpp/error/assert for more information.
Exceptions
invalid_iterator.201if iterators first and last are not compatible (i.e., do not belong to the same JSON value). In this case, the range [first, last) is undefined.
invalid_iterator.204if iterators first and last belong to a primitive type (number, boolean, or string), but first does not point to the first element any more. In this case, the range [first, last) is undefined. See example code below.
invalid_iterator.206if iterators first and last belong to a null value. In this case, the range [first, last) is undefined.

@complexity Linear in distance between first and last.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The example below shows several ways to create JSON values by specifying a subrange with iterators.,basic_json__InputIt_InputIt}

Since
version 1.0.0

Definition at line 18406 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::binary, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::boolean, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::boolean, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::JSON_ASSERT(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::number_float, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_float, nlohmann::detail::number_integer, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_integer, nlohmann::detail::number_unsigned, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_unsigned, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, nlohmann::detail::string, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

◆ basic_json() [8/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( const JsonRef &  ref)
inline

Definition at line 18509 of file json.h.

◆ basic_json() [9/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  other)
inline

copy constructor

Creates a copy of a given JSON value.

Parameters
[in]otherthe JSON value to copy
Postcondition
*this == other

@complexity Linear in the size of other.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is linear.
  • As postcondition, it holds: other == basic_json(other).

@liveexample{The following code shows an example for the copy constructor.,basic_json__basic_json}

Since
version 1.0.0

Definition at line 18536 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::binary, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::boolean, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::boolean, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::number_float, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_float, nlohmann::detail::number_integer, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_integer, nlohmann::detail::number_unsigned, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_unsigned, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, nlohmann::detail::string, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

◆ basic_json() [10/10]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &&  other)
inlinenoexcept

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.

Parameters
[in,out]othervalue to move to this object
Postcondition
*this has the same value as other before the call.
other is a JSON null value.

@complexity Constant.

@exceptionsafety No-throw guarantee: this constructor never throws exceptions.

@requirement This function helps basic_json satisfying the MoveConstructible requirements.

@liveexample{The code below shows the move constructor explicitly called via std::move.,basic_json__moveconstructor}

Since
version 1.0.0

Definition at line 18625 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), and nlohmann::detail::null.

◆ ~basic_json()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::~basic_json ( )
inlinenoexcept

Member Function Documentation

◆ accept() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType >
static bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::accept ( InputType &&  i,
const bool  ignore_comments = false 
)
inlinestatic

check if the input is valid JSON

Unlike the parse(InputType&&, const parser_callback_t,const bool) function, this function neither throws an exception in case of invalid JSON input (i.e., a parse error) nor creates diagnostic information.

Template Parameters
InputTypeA compatible input, for instance
  • an std::istream object
  • a FILE pointer
  • a C-style array of characters
  • a pointer to a null-terminated string of single byte characters
  • an object obj for which begin(obj) and end(obj) produces a valid pair of iterators.
Parameters
[in]iinput to read from
[in]ignore_commentswhether comments should be ignored and treated like whitespace (true) or yield a parse error (true); (optional, false by default)
Returns
Whether the input read from i is valid JSON.

@complexity Linear in the length of the input. The parser is a predictive LL(1) parser.

Note
A UTF-8 byte order mark is silently ignored.

@liveexample{The example below demonstrates the accept() function reading from a string.,accept__string}

Definition at line 23228 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::ignore_comments, nlohmann::detail::input_adapter(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parser().

◆ accept() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename IteratorType >
static bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::accept ( IteratorType  first,
IteratorType  last,
const bool  ignore_comments = false 
)
inlinestatic

◆ array()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::array ( initializer_list_t  init = {})
inlinestatic

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.

Note
This function is only needed to express two edge cases that cannot be realized with the initializer list constructor (basic_json(initializer_list_t, bool, value_t)). These cases are:
  1. creating an array whose elements are all pairs whose first element is a string – in this case, the initializer list constructor would create an object, taking the first elements as keys
  2. creating an empty array – passing the empty initializer list to the initializer list constructor yields an empty object
Parameters
[in]initinitializer list with JSON values to create an array from (optional)
Returns
JSON array value

@complexity Linear in the size of init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The following code shows an example for the array function.,array}

See also
basic_json(initializer_list_t, bool, value_t)create a JSON value from an initializer list
object(initializer_list_t)create a JSON object value from an initializer list
Since
version 1.0.0

Definition at line 18270 of file json.h.

Referenced by pyjson::to_json().

◆ assert_invariant()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant ( ) const
inlineprivatenoexcept

checks the class invariants

This function asserts the class invariants. It needs to be called at the end of every constructor to make sure that created objects respect the invariant. Furthermore, it has to be called each time the type of a JSON value is changed, because the invariant expresses a relationship between m_type and m_value.

Definition at line 17710 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::binary, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::JSON_ASSERT(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, nlohmann::detail::string, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace_back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator=(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[](), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::~basic_json().

◆ at() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]keykey of the element to access
Returns
reference to the element at key key
Exceptions
type_error.304if the JSON value is not an object; in this case, calling at with a key makes no sense. See example below.
out_of_range.403if the key key is is not stored in the object; that is, find(key) == end(). See example below.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Logarithmic in the size of the container.

See also
operator[](const typename object_t::key_type&) for unchecked access by reference
value() for access by value with a default value
Since
version 1.0.0

@liveexample{The example below shows how object elements can be read and written using at(). It also demonstrates the different exceptions that can be thrown.,at__object_t_key_type}

Definition at line 19891 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ at() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]keykey of the element to access
Returns
const reference to the element at key key
Exceptions
type_error.304if the JSON value is not an object; in this case, calling at with a key makes no sense. See example below.
out_of_range.403if the key key is is not stored in the object; that is, find(key) == end(). See example below.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Logarithmic in the size of the container.

See also
operator[](const typename object_t::key_type&) for unchecked access by reference
value() for access by value with a default value
Since
version 1.0.0

@liveexample{The example below shows how object elements can be read using at(). It also demonstrates the different exceptions that can be thrown., at__object_t_key_type_const}

Definition at line 19942 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ at() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]idxindex of the element to access
Returns
reference to the element at index idx
Exceptions
type_error.304if the JSON value is not an array; in this case, calling at with an index makes no sense. See example below.
out_of_range.401if the index idx is out of range of the array; that is, idx >= size(). See example below.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Constant.

Since
version 1.0.0

@liveexample{The example below shows how array elements can be read and written using at(). It also demonstrates the different exceptions that can be thrown.,at__size_type}

Definition at line 19793 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::to_string().

Referenced by umbridge::HTTPModel::HTTPModel(), and umbridge::serveModels().

◆ at() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]idxindex of the element to access
Returns
const reference to the element at index idx
Exceptions
type_error.304if the JSON value is not an array; in this case, calling at with an index makes no sense. See example below.
out_of_range.401if the index idx is out of range of the array; that is, idx >= size(). See example below.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Constant.

Since
version 1.0.0

@liveexample{The example below shows how array elements can be read using at(). It also demonstrates the different exceptions that can be thrown., at__size_type_const}

Definition at line 19840 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::to_string().

◆ back() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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

auto tmp = c.end();
--tmp;
return *tmp;
Returns
In case of a structured type (array or object), a reference to the last element is returned. In case of number, string, boolean, or binary values, a reference to the value is returned.

@complexity Constant.

Precondition
The JSON value must not be null (would throw std::out_of_range) or an empty array or object (undefined behavior, guarded by assertions).
Postcondition
The JSON value remains unchanged.
Exceptions
invalid_iterator.214when called on a null value. See example below.

@liveexample{The following code shows an example for back().,back}

See also
front() – access the first element
Since
version 1.0.0

Definition at line 20449 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end().

◆ back() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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

auto tmp = c.end();
--tmp;
return *tmp;
Returns
In case of a structured type (array or object), a reference to the last element is returned. In case of number, string, boolean, or binary values, a reference to the value is returned.

@complexity Constant.

Precondition
The JSON value must not be null (would throw std::out_of_range) or an empty array or object (undefined behavior, guarded by assertions).
Postcondition
The JSON value remains unchanged.
Exceptions
invalid_iterator.214when called on a null value. See example below.

@liveexample{The following code shows an example for back().,back}

See also
front() – access the first element
Since
version 1.0.0

Definition at line 20459 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cend().

◆ begin() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::begin ( ) const
inlinenoexcept

returns a const iterator to the first element

Returns a const iterator to the first element.

Illustration from cppreference.com
Returns
const iterator to the first element

@complexity Constant.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).begin().

@liveexample{The following code shows an example for cbegin().,cbegin}

See also
begin() – returns an iterator to the beginning
end() – returns an iterator to the end
cend() – returns a const iterator to the end
Since
version 1.0.0

Definition at line 20976 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cbegin().

◆ begin() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::begin ( )
inlinenoexcept

returns an iterator to the first element

Returns an iterator to the first element.

Illustration from cppreference.com
Returns
iterator to the first element

@complexity Constant.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.

@liveexample{The following code shows an example for begin().,begin}

See also
cbegin() – returns a const iterator to the beginning
end() – returns an iterator to the end
cend() – returns a const iterator to the end
Since
version 1.0.0

Definition at line 20966 of file json.h.

References nlohmann::detail::iter_impl< BasicJsonType >::set_begin().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::front(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rend().

◆ binary() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary ( const typename binary_t::container_type init)
inlinestatic

explicitly create a binary array (without subtype)

Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.

Note
Note, this function exists because of the difficulty in correctly specifying the correct template overload in the standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a std::vector. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
Parameters
[in]initcontainer containing bytes to use as binary type
Returns
JSON binary array value

@complexity Linear in the size of init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

Since
version 3.8.0

Definition at line 18167 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), and nlohmann::detail::binary.

◆ binary() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary ( const typename binary_t::container_type init,
std::uint8_t  subtype 
)
inlinestatic

explicitly create a binary array (with subtype)

Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.

Note
Note, this function exists because of the difficulty in correctly specifying the correct template overload in the standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a std::vector. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
Parameters
[in]initcontainer containing bytes to use as binary type
[in]subtypesubtype to use in MessagePack and BSON
Returns
JSON binary array value

@complexity Linear in the size of init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

Since
version 3.8.0

Definition at line 18204 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), and nlohmann::detail::binary.

◆ binary() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary ( typename binary_t::container_type &&  init)
inlinestatic

explicitly create a binary array (without subtype)

Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.

Note
Note, this function exists because of the difficulty in correctly specifying the correct template overload in the standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a std::vector. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
Parameters
[in]initcontainer containing bytes to use as binary type
Returns
JSON binary array value

@complexity Linear in the size of init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

Since
version 3.8.0

Definition at line 18214 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), and nlohmann::detail::binary.

◆ binary() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::binary ( typename binary_t::container_type &&  init,
std::uint8_t  subtype 
)
inlinestatic

explicitly create a binary array (with subtype)

Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.

Note
Note, this function exists because of the difficulty in correctly specifying the correct template overload in the standard value ctor, as both JSON arrays and JSON binary arrays are backed with some form of a std::vector. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.
Parameters
[in]initcontainer containing bytes to use as binary type
[in]subtypesubtype to use in MessagePack and BSON
Returns
JSON binary array value

@complexity Linear in the size of init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

Since
version 3.8.0

Definition at line 18224 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), and nlohmann::detail::binary.

◆ cbegin()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cend ( ) const
inlinenoexcept

returns a const iterator to one past the last element

Returns a const iterator to one past the last element.

Illustration from cppreference.com
Returns
const iterator one past the last element

@complexity Constant.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).end().

@liveexample{The following code shows an example for cend().,cend}

See also
end() – returns an iterator to the end
begin() – returns an iterator to the beginning
cbegin() – returns a const iterator to the beginning
Since
version 1.0.0

Definition at line 21077 of file json.h.

References nlohmann::detail::iter_impl< BasicJsonType >::set_end().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::crbegin(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find(), pyjson::from_json(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update().

◆ clear()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::clear ( )
inlinenoexcept

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 with the current value type from type():

Value type initial value
null null
boolean false
string ""
number 0
binary An empty byte vector
object {}
array []
Postcondition
Has the same effect as calling
*this = basic_json(type());
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.h:18812

@liveexample{The example below shows the effect of clear() to different JSON types.,clear}

@complexity Linear in the size of the JSON value.

@iterators All iterators, pointers and references related to this container are invalidated.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

See also
basic_json(value_t) – constructor that creates an object with the same value than calling clear()
Since
version 1.0.0

Definition at line 21636 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::binary, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::boolean, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::boolean, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::number_float, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_float, nlohmann::detail::number_integer, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_integer, nlohmann::detail::number_unsigned, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::number_unsigned, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, nlohmann::detail::string, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

◆ contains() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::contains ( const json_pointer ptr) const
inline

check the existence of an element in a JSON object given a JSON pointer

Check whether the given JSON pointer ptr can be resolved in the current JSON value.

Note
This method can be executed on any JSON value type.
Parameters
[in]ptrJSON pointer to check its existence.
Returns
true if the JSON pointer can be resolved to a stored value, false otherwise.
Postcondition
If j.contains(ptr) returns true, it is safe to call j[ptr].
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index was not a number

@complexity Logarithmic in the size of the JSON object.

@liveexample{The following code shows an example for contains().,contains_json_pointer}

See also
contains(KeyT &&) const – checks the existence of a key
Since
version 3.7.0

Definition at line 20927 of file json.h.

References nlohmann::json_pointer< BasicJsonType >::contains().

◆ contains() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename KeyT , typename std::enable_if< !std::is_same< typename std::decay< KeyT >::type, json_pointer >::value, int >::type = 0>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::contains ( KeyT &&  key) const
inline

check the existence of an element in a JSON object

Check whether an element exists in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, false is returned.

Note
This method always returns false when executed on a JSON type that is not an object.
Parameters
[in]keykey value to check its existence.
Returns
true if an element with specified key exists. If no such element with such key is found or the JSON value is not an object, false is returned.

@complexity Logarithmic in the size of the JSON object.

@liveexample{The following code shows an example for contains().,contains}

See also
find(KeyT&&) – returns an iterator to an object element
contains(const json_pointer&) const – checks the existence for a JSON pointer
Since
version 3.6.0

Definition at line 20896 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ count()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename KeyT >
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::count ( KeyT &&  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).

Note
This method always returns 0 when executed on a JSON type that is not an object.
Parameters
[in]keykey value of the element to count
Returns
Number of elements with key key. If the JSON value is not an object, the return value will be 0.

@complexity Logarithmic in the size of the JSON object.

@liveexample{The example shows how count() is used.,count}

Since
version 1.0.0

Definition at line 20863 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ crbegin()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::crbegin ( ) const
inlinenoexcept

returns a const reverse iterator to the last element

Returns a const iterator to the reverse-beginning; that is, the last element.

Illustration from cppreference.com

@complexity Constant.

@requirement This function helps basic_json satisfying the ReversibleContainer requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).rbegin().

@liveexample{The following code shows an example for crbegin().,crbegin}

See also
rbegin() – returns a reverse iterator to the beginning
rend() – returns a reverse iterator to the end
crend() – returns a const reverse iterator to the end
Since
version 1.0.0

Definition at line 21181 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cend().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rbegin().

◆ create()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename T , typename... Args>
static JSON_HEDLEY_RETURNS_NON_NULL T* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::create ( Args &&...  args)
inlinestaticprivate

◆ crend()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::crend ( ) const
inlinenoexcept

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.

Illustration from cppreference.com

@complexity Constant.

@requirement This function helps basic_json satisfying the ReversibleContainer requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).rend().

@liveexample{The following code shows an example for crend().,crend}

See also
rend() – returns a reverse iterator to the end
rbegin() – returns a reverse iterator to the beginning
crbegin() – returns a const reverse iterator to the beginning
Since
version 1.0.0

Definition at line 21210 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cbegin().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rend().

◆ dump()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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
inline

serialization

Serialization function for JSON values. The function tries to mimic Python's json.dumps() function, and currently supports its indent and ensure_ascii parameters.

Parameters
[in]indentIf 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.
[in]indent_charThe character to use for indentation if indent is greater than 0. The default is (space).
[in]ensure_asciiIf ensure_ascii is true, all non-ASCII characters in the output are escaped with \uXXXX sequences, and the result consists of ASCII characters only.
[in]error_handlerhow to react on decoding errors; there are three possible values: strict (throws and exception in case a decoding error occurs; default), replace (replace invalid UTF-8 sequences with U+FFFD), and ignore (ignore invalid UTF-8 sequences during serialization; all bytes are copied to the output unchanged).
Returns
string containing the serialization of the JSON value
Exceptions
type_error.316if a string stored inside the JSON value is not UTF-8 encoded and error_handler is set to strict
Note
Binary values are serialized as object containing two keys:
  • "bytes": an array of bytes as integers
  • "subtype": the subtype as integer or "null" if the binary has no subtype

@complexity Linear.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@liveexample{The following example shows the effect of different indent\, indent_char\, and ensure_ascii parameters to the result of the serialization.,dump}

See also
https://docs.python.org/2/library/json.html#json.dump
Since
version 1.0.0; indentation character indent_char, option ensure_ascii and exceptions added in version 3.0.0; error handlers added in version 3.4.0; serialization of binary values added in version 3.8.0.

Definition at line 18759 of file json.h.

References nlohmann::detail::serializer< BasicJsonType >::dump().

Referenced by umbridge::HTTPModel::ApplyHessian(), umbridge::HTTPModel::ApplyJacobian(), umbridge::check_input_sizes(), umbridge::check_input_wrt(), umbridge::check_model_exists(), umbridge::check_output_sizes(), umbridge::check_output_wrt(), umbridge::check_sensitivity_size(), umbridge::check_vector_size(), umbridge::HTTPModel::Evaluate(), umbridge::HTTPModel::GetInputSizes(), umbridge::HTTPModel::GetOutputSizes(), umbridge::HTTPModel::Gradient(), umbridge::HTTPModel::HTTPModel(), umbridge::serveModels(), and umbridge::write_unsupported_feature_response().

◆ emplace()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<class... Args>
std::pair<iterator, bool> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace ( Args &&...  args)
inline

add an object to an object if key does not exist

Inserts a new element into a JSON object constructed in-place with the given args if there is no element with the key in the container. If the function is called on a JSON null value, an empty object is created before appending the value created from args.

Parameters
[in]argsarguments to forward to a constructor of basic_json
Template Parameters
Argscompatible types to create a basic_json object
Returns
a pair consisting of an iterator to the inserted element, or the already-existing element if no insertion happened, and a bool denoting whether the insertion took place.
Exceptions
type_error.311when called on a type other than JSON object or null; example: "cannot use emplace() with number"

@complexity Logarithmic in the size of the container, O(log(size())).

@liveexample{The example shows how emplace() can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object. Further note how no value is added if there was already one value stored with the same key.,emplace}

Since
version 2.0.8

Definition at line 21954 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::begin(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ emplace_back()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<class... Args>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace_back ( Args &&...  args)
inline

add an object to an array

Creates a JSON value from the passed parameters args to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending the value created from args.

Parameters
[in]argsarguments to forward to a constructor of basic_json
Template Parameters
Argscompatible types to create a basic_json object
Returns
reference to the inserted element
Exceptions
type_error.311when called on a type other than JSON array or null; example: "cannot use emplace_back() with number"

@complexity Amortized constant.

@liveexample{The example shows how push_back() can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.,emplace_back}

Since
version 2.0.8, returns reference since 3.7.0

Definition at line 21901 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ empty()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::empty ( ) const
inlinenoexcept

checks whether the container is empty.

Checks if a JSON value has no elements (i.e. whether its size is 0).

Returns
The return value depends on the different types and is defined as follows:
Value type return value
null true
boolean false
string false
number false
binary false
object result of function object_t::empty()
array result of function array_t::empty()

@liveexample{The following code uses empty() to check if a JSON object contains any elements.,empty}

@complexity Constant, as long as array_t and object_t satisfy the Container concept; that is, their empty() functions have constant complexity.

@iterators No changes.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

Note
This function does not return whether a string stored as JSON value is empty - it returns whether the JSON container itself is empty which is false in the case of a string.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of begin() == end().
See also
size() – returns the number of elements
Since
version 1.0.0

Definition at line 21421 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::null, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ end() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end ( ) const
inlinenoexcept

returns a const iterator to one past the last element

Returns a const iterator to one past the last element.

Illustration from cppreference.com
Returns
const iterator one past the last element

@complexity Constant.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).end().

@liveexample{The following code shows an example for cend().,cend}

See also
end() – returns an iterator to the end
begin() – returns an iterator to the beginning
cbegin() – returns a const iterator to the beginning
Since
version 1.0.0

Definition at line 21047 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cend().

◆ end() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end ( )
inlinenoexcept

returns an iterator to one past the last element

Returns an iterator to one past the last element.

Illustration from cppreference.com
Returns
iterator one past the last element

@complexity Constant.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.

@liveexample{The following code shows an example for end().,end}

See also
cend() – returns a const iterator to the end
begin() – returns an iterator to the beginning
cbegin() – returns a const iterator to the beginning
Since
version 1.0.0

Definition at line 21037 of file json.h.

References nlohmann::detail::iter_impl< BasicJsonType >::set_end().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rbegin(), umbridge::HTTPModel::throw_if_error_in_response(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value().

◆ erase() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]idxindex of the element to remove
Exceptions
type_error.307when called on a type other than JSON object; example: "cannot use erase() with null"
out_of_range.401when idx >= size(); example: "array index 17 is out of range"

@complexity Linear in distance between idx and the end of the container.

@liveexample{The example shows the effect of erase().,erase__size_type}

See also
erase(IteratorType) – removes the element at a given position
erase(IteratorType, IteratorType) – removes the elements in the given range
erase(const typename object_t::key_type&) – removes the element from an object at the given key
Since
version 1.0.0

Definition at line 20759 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::size(), and nlohmann::to_string().

◆ erase() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]keyvalue of the elements to remove
Returns
Number of elements removed. If ObjectType is the default std::map type, the return value will always be 0 (key was not found) or 1 (key was found).
Postcondition
References and iterators to the erased elements are invalidated. Other references and iterators are not affected.
Exceptions
type_error.307when called on a type other than JSON object; example: "cannot use erase() with null"

@complexity log(size()) + count(key)

@liveexample{The example shows the effect of erase().,erase__key_type}

See also
erase(IteratorType) – removes the element at a given position
erase(IteratorType, IteratorType) – removes the elements in the given range
erase(const size_type) – removes the element from an array at the given index
Since
version 1.0.0

Definition at line 20724 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ erase() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase ( IteratorType  first,
IteratorType  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.

Parameters
[in]firstiterator to the beginning of the range to remove
[in]lastiterator past the end of the range to remove
Returns
Iterator following the last removed element. If the iterator second refers to the last element, the end() iterator is returned.
Template Parameters
IteratorTypean iterator or const_iterator
Postcondition
Invalidates iterators and references at or after the point of the erase, including the end() iterator.
Exceptions
type_error.307if called on a null value; example: "cannot use erase() with null"
invalid_iterator.203if called on iterators which does not belong to the current JSON value; example: "iterators do not fit current value"
invalid_iterator.204if called on a primitive type with invalid iterators (i.e., if first != begin() and last != end()); example: "iterators out of range"

@complexity The complexity depends on the type:

  • objects: log(size()) + std::distance(first, last)
  • arrays: linear in the distance between first and last, plus linear in the distance between last and end of the container
  • strings and binary: linear in the length of the member
  • other types: constant

@liveexample{The example shows the result of erase() for different JSON types.,erase__IteratorType_IteratorType}

See also
erase(IteratorType) – removes the element at a given position
erase(const typename object_t::key_type&) – removes the element from an object at the given key
erase(const size_type) – removes the element from an array at the given index
Since
version 1.0.0

Definition at line 20629 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::binary, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::boolean, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_string(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, nlohmann::detail::string, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

◆ erase() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase ( IteratorType  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.

Parameters
[in]positerator to the element to remove
Returns
Iterator following the last removed element. If the iterator pos refers to the last element, the end() iterator is returned.
Template Parameters
IteratorTypean iterator or const_iterator
Postcondition
Invalidates iterators and references at or after the point of the erase, including the end() iterator.
Exceptions
type_error.307if called on a null value; example: "cannot use erase() with null"
invalid_iterator.202if called on an iterator which does not belong to the current JSON value; example: "iterator does not fit current value"
invalid_iterator.205if called on a primitive type with invalid iterator (i.e., any iterator which is not begin()); example: "iterator out of range"

@complexity The complexity depends on the type:

  • objects: amortized constant
  • arrays: linear in distance between pos and the end of the container
  • strings and binary: linear in the length of the member
  • other types: constant

@liveexample{The example shows the result of erase() for different JSON types.,erase__IteratorType}

See also
erase(IteratorType, IteratorType) – removes the elements in the given range
erase(const typename object_t::key_type&) – removes the element from an object at the given key
erase(const size_type) – removes the element from an array at the given index
Since
version 1.0.0

Definition at line 20516 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::binary, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::boolean, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_string(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, nlohmann::detail::string, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

◆ find() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename KeyT >
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find ( KeyT &&  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.

Note
This method always returns end() when executed on a JSON type that is not an object.
Parameters
[in]keykey value of the element to search for.
Returns
Iterator to an element with key equivalent to key. If no such element is found or the JSON value is not an object, past-the-end (see end()) iterator is returned.

@complexity Logarithmic in the size of the JSON object.

@liveexample{The example shows how find() is used.,find__key_type}

See also
contains(KeyT&&) const – checks whether a key exists
Since
version 1.0.0

Definition at line 20812 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

Referenced by umbridge::HTTPModel::throw_if_error_in_response(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value().

◆ find() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename KeyT >
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find ( KeyT &&  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.

Note
This method always returns end() when executed on a JSON type that is not an object.
Parameters
[in]keykey value of the element to search for.
Returns
Iterator to an element with key equivalent to key. If no such element is found or the JSON value is not an object, past-the-end (see end()) iterator is returned.

@complexity Logarithmic in the size of the JSON object.

@liveexample{The example shows how find() is used.,find__key_type}

See also
contains(KeyT&&) const – checks whether a key exists
Since
version 1.0.0

Definition at line 20829 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cend(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ from_cbor() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType >
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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 
)
inlinestatic

create a JSON value from an input in CBOR format

Deserializes a given input i to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.

The library maps CBOR types to JSON value types as follows:

CBOR type JSON value type first byte
Integer number_unsigned 0x00..0x17
Unsigned integer number_unsigned 0x18
Unsigned integer number_unsigned 0x19
Unsigned integer number_unsigned 0x1A
Unsigned integer number_unsigned 0x1B
Negative integer number_integer 0x20..0x37
Negative integer number_integer 0x38
Negative integer number_integer 0x39
Negative integer number_integer 0x3A
Negative integer number_integer 0x3B
Byte string binary 0x40..0x57
Byte string binary 0x58
Byte string binary 0x59
Byte string binary 0x5A
Byte string binary 0x5B
UTF-8 string string 0x60..0x77
UTF-8 string string 0x78
UTF-8 string string 0x79
UTF-8 string string 0x7A
UTF-8 string string 0x7B
UTF-8 string string 0x7F
array array 0x80..0x97
array array 0x98
array array 0x99
array array 0x9A
array array 0x9B
array array 0x9F
map object 0xA0..0xB7
map object 0xB8
map object 0xB9
map object 0xBA
map object 0xBB
map object 0xBF
False false 0xF4
True true 0xF5
Null null 0xF6
Half-Precision Float number_float 0xF9
Single-Precision Float number_float 0xFA
Double-Precision Float number_float 0xFB
Warning
The mapping is incomplete in the sense that not all CBOR types can be converted to a JSON value. The following CBOR types are not supported and will yield parse errors (parse_error.112):
  • date/time (0xC0..0xC1)
  • bignum (0xC2..0xC3)
  • decimal fraction (0xC4)
  • bigfloat (0xC5)
  • expected conversions (0xD5..0xD7)
  • simple values (0xE0..0xF3, 0xF8)
  • undefined (0xF7)
CBOR allows map keys of any type, whereas JSON only allows strings as keys in object values. Therefore, CBOR maps with keys other than UTF-8 strings are rejected (parse_error.113).
Note
Any CBOR output created to_cbor can be successfully parsed by from_cbor.
Parameters
[in]ian input in CBOR format convertible to an input adapter
[in]strictwhether to expect the input to be consumed until EOF (true by default)
[in]allow_exceptionswhether to throw exceptions in case of a parse error (optional, true by default)
[in]tag_handlerhow to treat CBOR tags (optional, error by default)
Returns
deserialized JSON value; in case of a parse error and allow_exceptions set to false, the return value will be value_t::discarded.
Exceptions
parse_error.110if the given input ends prematurely or the end of file was not reached when strict was set to true
parse_error.112if unsupported features from CBOR were used in the given input v or if the input is not valid CBOR
parse_error.113if a string was expected as map key, but not found

@complexity Linear in the size of the input i.

@liveexample{The example shows the deserialization of a byte vector in CBOR format to a JSON value.,from_cbor}

See also
http://cbor.io
to_cbor(const basic_json&) for the analogous serialization
from_msgpack(detail::input_adapter&&, const bool, const bool) for the related MessagePack format
from_ubjson(detail::input_adapter&&, const bool, const bool) for the related UBJSON format
Since
version 2.0.9; parameter start_index since 2.1.1; changed to consume input adapters, removed start_index parameter, and added strict parameter since 3.0.0; added allow_exceptions parameter since 3.2.0; added tag_handler parameter since 3.9.0.

Definition at line 23960 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::allow_exceptions, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::strict.

◆ from_cbor() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename IteratorType >
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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 
)
inlinestatic

◆ front() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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().

Returns
In case of a structured type (array or object), a reference to the first element is returned. In case of number, string, boolean, or binary values, a reference to the value is returned.

@complexity Constant.

Precondition
The JSON value must not be null (would throw std::out_of_range) or an empty array or object (undefined behavior, guarded by assertions).
Postcondition
The JSON value remains unchanged.
Exceptions
invalid_iterator.214when called on null value

@liveexample{The following code shows an example for front().,front}

See also
back() – access the last element
Since
version 1.0.0

Definition at line 20405 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::begin().

◆ front() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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().

Returns
In case of a structured type (array or object), a reference to the first element is returned. In case of number, string, boolean, or binary values, a reference to the value is returned.

@complexity Constant.

Precondition
The JSON value must not be null (would throw std::out_of_range) or an empty array or object (undefined behavior, guarded by assertions).
Postcondition
The JSON value remains unchanged.
Exceptions
invalid_iterator.214when called on null value

@liveexample{The following code shows an example for front().,front}

See also
back() – access the last element
Since
version 1.0.0

Definition at line 20413 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cbegin().

◆ get() [1/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType , detail::enable_if_t< std::is_same< typename std::remove_const< BasicJsonType >::type, basic_json_t >::value, int > = 0>
basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get ( ) const
inline

◆ get() [2/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType , detail::enable_if_t< !std::is_same< BasicJsonType, basic_json >::value &&detail::is_basic_json< BasicJsonType >::value, int > = 0>
BasicJsonType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get ( ) const
inline

get special-case overload

This overloads converts the current basic_json in a different basic_json type

Template Parameters
BasicJsonType== basic_json
Returns
a copy of *this, converted into
Template Parameters
BasicJsonType@complexity Depending on the implementation of the called from_json() method.
Since
version 3.2.0

Definition at line 19359 of file json.h.

◆ get() [3/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
constexpr auto nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get ( ) const -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
inlineconstexprnoexcept

get a pointer value (explicit)

get a pointer value (explicit) Explicit pointer access to the internally stored JSON value. No copies are made.

Warning
The pointer becomes invalid if the underlying JSON object changes.
Template Parameters
PointerTypepointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t.
Returns
pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise

@complexity Constant.

@liveexample{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}

See also
get_ptr() for explicit pointer-member access
Since
version 1.0.0

Definition at line 19627 of file json.h.

◆ get() [4/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get ( ) const
inlinenoexcept

get a value (explicit); special case

Explicit type conversion between the JSON value and a compatible value which is not CopyConstructible and not DefaultConstructible. The value is converted by calling the json_serializer<ValueType> from_json() method.

The function is equivalent to executing

py::object from_json(const nl::json &j)
Definition: pybind11_json.h:24

This overloads is chosen if:

Note
If json_serializer<ValueType> has both overloads of from_json(), this one is chosen.
Template Parameters
ValueTypeCVthe provided value type
ValueTypethe returned value type
Returns
copy of the JSON value, converted to ValueType
Exceptions
whatjson_serializer<ValueType> from_json() method throws
Since
version 2.1.0

Definition at line 19460 of file json.h.

References nlohmann::detail::from_json(), and nlohmann::detail::value.

◆ get() [5/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get ( ) const
inlinenoexcept

get a value (explicit)

Explicit type conversion between the JSON value and a compatible value which is CopyConstructible and DefaultConstructible. The value is converted by calling the json_serializer<ValueType> from_json() method.

The function is equivalent to executing

ValueType ret;
return ret;

This overloads is chosen if:

Template Parameters
ValueTypeCVthe provided value type
ValueTypethe returned value type
Returns
copy of the JSON value, converted to ValueType
Exceptions
whatjson_serializer<ValueType> from_json() method throws

@liveexample{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}

Since
version 2.1.0

Definition at line 19409 of file json.h.

References nlohmann::detail::from_json(), and nlohmann::detail::value.

◆ get() [6/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
auto nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get ( ) -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
inlinenoexcept

get a pointer value (explicit)

Explicit pointer access to the internally stored JSON value. No copies are made.

Warning
The pointer becomes invalid if the underlying JSON object changes.
Template Parameters
PointerTypepointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t.
Returns
pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise

@complexity Constant.

@liveexample{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}

See also
get_ptr() for explicit pointer-member access
Since
version 1.0.0

Definition at line 19615 of file json.h.

◆ get_allocator()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static allocator_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_allocator ( )
inlinestatic

returns the allocator associated with the container

Definition at line 16799 of file json.h.

◆ get_binary() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
binary_t& nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_binary ( )
inline
Returns
reference to the binary value
Exceptions
type_error.302if the value is not binary
See also
is_binary() to check if the value is binary
Since
version 3.8.0

Definition at line 19735 of file json.h.

References nlohmann::detail::type_error::create(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary().

◆ get_binary() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const binary_t& nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_binary ( ) const
inline

Returns
reference to the binary value
Exceptions
type_error.302if the value is not binary
See also
is_binary() to check if the value is binary
Since
version 3.8.0

Definition at line 19746 of file json.h.

References nlohmann::detail::type_error::create(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary().

◆ get_impl()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
boolean_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl ( boolean_t ) const
inlineprivate

◆ get_impl_ptr() [1/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
array_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( array_t )
inlineprivatenoexcept

◆ get_impl_ptr() [2/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
binary_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( binary_t )
inlineprivatenoexcept

◆ get_impl_ptr() [3/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
boolean_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( boolean_t )
inlineprivatenoexcept

◆ get_impl_ptr() [4/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const array_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const array_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [5/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const binary_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const binary_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [6/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const boolean_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const boolean_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [7/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const number_float_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const number_float_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [8/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const number_integer_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const number_integer_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [9/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const number_unsigned_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const number_unsigned_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [10/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const object_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const object_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [11/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr const string_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( const string_t ) const
inlineconstexprprivatenoexcept

◆ get_impl_ptr() [12/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
number_float_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( number_float_t )
inlineprivatenoexcept

◆ get_impl_ptr() [13/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
number_integer_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( number_integer_t )
inlineprivatenoexcept

◆ get_impl_ptr() [14/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
number_unsigned_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( number_unsigned_t )
inlineprivatenoexcept

◆ get_impl_ptr() [15/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
object_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( object_t )
inlineprivatenoexcept

◆ get_impl_ptr() [16/16]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
string_t* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr ( string_t )
inlineprivatenoexcept

◆ get_ptr() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_ptr ( ) const -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
inlineconstexprnoexcept

get a pointer value (implicit)

get a pointer value (implicit) Implicit pointer access to the internally stored JSON value. No copies are made.

Warning
Writing data to the pointee of the result yields an undefined state.
Template Parameters
PointerTypepointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. Enforced by a static assertion.
Returns
pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise

@complexity Constant.

@liveexample{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}

Since
version 1.0.0

Definition at line 19580 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr().

◆ get_ptr() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
auto nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_ptr ( ) -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
inlinenoexcept

get a pointer value (implicit)

Implicit pointer access to the internally stored JSON value. No copies are made.

Warning
Writing data to the pointee of the result yields an undefined state.
Template Parameters
PointerTypepointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. Enforced by a static assertion.
Returns
pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise

@complexity Constant.

@liveexample{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}

Since
version 1.0.0

Definition at line 19567 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr().

◆ get_ref() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value, int >::type = 0>
ReferenceType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_ref ( )
inline

get a reference value (implicit)

Implicit reference access to the internally stored JSON value. No copies are made.

Warning
Writing data to the referee of the result yields an undefined state.
Template Parameters
ReferenceTypereference type; must be a reference to array_t, object_t, string_t, boolean_t, number_integer_t, or number_float_t. Enforced by static assertion.
Returns
reference to the internally stored JSON value if the requested reference type ReferenceType fits to the JSON value; throws type_error.303 otherwise
Exceptions
type_error.303in case passed type ReferenceType is incompatible with the stored JSON value; see example below

@complexity Constant.

@liveexample{The example shows several calls to get_ref().,get_ref}

Since
version 1.1.0

Definition at line 19661 of file json.h.

◆ get_ref() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_ref ( ) const
inline

get a reference value (implicit)

get a reference value (implicit) Implicit reference access to the internally stored JSON value. No copies are made.

Warning
Writing data to the referee of the result yields an undefined state.
Template Parameters
ReferenceTypereference type; must be a reference to array_t, object_t, string_t, boolean_t, number_integer_t, or number_float_t. Enforced by static assertion.
Returns
reference to the internally stored JSON value if the requested reference type ReferenceType fits to the JSON value; throws type_error.303 otherwise
Exceptions
type_error.303in case passed type ReferenceType is incompatible with the stored JSON value; see example below

@complexity Constant.

@liveexample{The example shows several calls to get_ref().,get_ref}

Since
version 1.1.0

Definition at line 19674 of file json.h.

◆ get_ref_impl()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ReferenceType , typename ThisType >
static ReferenceType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_ref_impl ( ThisType &  obj)
inlinestaticprivate

helper function to implement get_ref()

This function helps to implement get_ref() without code duplication for const and non-const overloads

Template Parameters
ThisTypewill be deduced as basic_json or const basic_json
Exceptions
type_error.303if ReferenceType does not match underlying value type of the current JSON

Definition at line 19301 of file json.h.

References nlohmann::detail::type_error::create().

◆ get_to() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_to ( T(&)  v[N]) const
inlinenoexcept

Definition at line 19530 of file json.h.

References nlohmann::detail::from_json(), and nlohmann::detail::dtoa_impl::v.

◆ get_to() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ValueType , detail::enable_if_t< detail::is_basic_json< ValueType >::value, int > = 0>
ValueType& nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_to ( ValueType &  v) const
inline

Definition at line 19519 of file json.h.

References nlohmann::detail::dtoa_impl::v.

◆ get_to() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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& nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_to ( ValueType &  v) const
inlinenoexcept

get a value (explicit)

Explicit type conversion between the JSON value and a compatible value. The value is filled into the input parameter by calling the json_serializer<ValueType> from_json() method.

The function is equivalent to executing

ValueType v;
int int diyfp diyfp v
Definition: json.h:15163

This overloads is chosen if:

Template Parameters
ValueTypethe input parameter type.
Returns
the input parameter, allowing chaining calls.
Exceptions
whatjson_serializer<ValueType> from_json() method throws

@liveexample{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_to}

Since
version 3.3.0

Definition at line 19506 of file json.h.

References nlohmann::detail::from_json(), and nlohmann::detail::dtoa_impl::v.

◆ insert() [1/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert ( const_iterator  first,
const_iterator  last 
)
inline

inserts elements

Inserts elements from range [first, last).

Parameters
[in]firstbegin of the range of elements to insert
[in]lastend of the range of elements to insert
Exceptions
type_error.309if called on JSON values other than objects; example: "cannot use insert() with string"
invalid_iterator.202if iterator first or last does does not point to an object; example: "iterators first and last must point to objects"
invalid_iterator.210if first and last do not belong to the same JSON value; example: "iterators do not fit"

@complexity Logarithmic: O(N*log(size() + N)), where N is the number of elements to insert.

@liveexample{The example shows how insert() is used.,insert__range_object}

Since
version 3.0.0

Definition at line 22215 of file json.h.

References nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last, nlohmann::detail::iter_impl< BasicJsonType >::m_it, nlohmann::detail::iter_impl< BasicJsonType >::m_object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, and nlohmann::detail::internal_iterator< BasicJsonType >::object_iterator.

◆ insert() [2/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert ( const_iterator  pos,
basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &&  val 
)
inline

inserts element

inserts element Inserts element val before iterator pos.

Parameters
[in]positerator before which the content will be inserted; may be the end() iterator
[in]valelement to insert
Returns
iterator pointing to the inserted val.
Exceptions
type_error.309if called on JSON values other than arrays; example: "cannot use insert() with string"
invalid_iterator.202if pos is not an iterator of *this; example: "iterator does not fit current value"

@complexity Constant plus linear in the distance between pos and end of the container.

@liveexample{The example shows how insert() is used.,insert}

Since
version 1.0.0

Definition at line 22044 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert().

◆ insert() [3/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert ( const_iterator  pos,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  val 
)
inline

inserts element

Inserts element val before iterator pos.

Parameters
[in]positerator before which the content will be inserted; may be the end() iterator
[in]valelement to insert
Returns
iterator pointing to the inserted val.
Exceptions
type_error.309if called on JSON values other than arrays; example: "cannot use insert() with string"
invalid_iterator.202if pos is not an iterator of *this; example: "iterator does not fit current value"

@complexity Constant plus linear in the distance between pos and end of the container.

@liveexample{The example shows how insert() is used.,insert}

Since
version 1.0.0

Definition at line 22022 of file json.h.

References nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert_iterator(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), and nlohmann::detail::iter_impl< BasicJsonType >::m_object.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert().

◆ insert() [4/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert ( const_iterator  pos,
const_iterator  first,
const_iterator  last 
)
inline

inserts elements

Inserts elements from range [first, last) before iterator pos.

Parameters
[in]positerator before which the content will be inserted; may be the end() iterator
[in]firstbegin of the range of elements to insert
[in]lastend of the range of elements to insert
Exceptions
type_error.309if called on JSON values other than arrays; example: "cannot use insert() with string"
invalid_iterator.202if pos is not an iterator of *this; example: "iterator does not fit current value"
invalid_iterator.210if first and last do not belong to the same JSON value; example: "iterators do not fit"
invalid_iterator.211if first or last are iterators into container for which insert is called; example: "passed iterators may not belong to container"
Returns
iterator pointing to the first element inserted, or pos if first==last

@complexity Linear in std::distance(first, last) plus linear in the distance between pos and end of the container.

@liveexample{The example shows how insert() is used.,insert__range}

Since
version 1.0.0

Definition at line 22121 of file json.h.

References nlohmann::detail::internal_iterator< BasicJsonType >::array_iterator, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert_iterator(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last, nlohmann::detail::iter_impl< BasicJsonType >::m_it, and nlohmann::detail::iter_impl< BasicJsonType >::m_object.

◆ insert() [5/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert ( const_iterator  pos,
initializer_list_t  ilist 
)
inline

inserts elements

Inserts elements from initializer list ilist before iterator pos.

Parameters
[in]positerator before which the content will be inserted; may be the end() iterator
[in]ilistinitializer list to insert the values from
Exceptions
type_error.309if called on JSON values other than arrays; example: "cannot use insert() with string"
invalid_iterator.202if pos is not an iterator of *this; example: "iterator does not fit current value"
Returns
iterator pointing to the first element inserted, or pos if ilist is empty

@complexity Linear in ilist.size() plus linear in the distance between pos and end of the container.

@liveexample{The example shows how insert() is used.,insert__ilist}

Since
version 1.0.0

Definition at line 22174 of file json.h.

References nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert_iterator(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), and nlohmann::detail::iter_impl< BasicJsonType >::m_object.

◆ insert() [6/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert ( const_iterator  pos,
size_type  cnt,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  val 
)
inline

inserts elements

Inserts cnt copies of val before iterator pos.

Parameters
[in]positerator before which the content will be inserted; may be the end() iterator
[in]cntnumber of copies of val to insert
[in]valelement to insert
Returns
iterator pointing to the first element inserted, or pos if cnt==0
Exceptions
type_error.309if called on JSON values other than arrays; example: "cannot use insert() with string"
invalid_iterator.202if pos is not an iterator of *this; example: "iterator does not fit current value"

@complexity Linear in cnt plus linear in the distance between pos and end of the container.

@liveexample{The example shows how insert() is used.,insert__count}

Since
version 1.0.0

Definition at line 22073 of file json.h.

References nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert_iterator(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), and nlohmann::detail::iter_impl< BasicJsonType >::m_object.

◆ insert_iterator()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename... Args>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert_iterator ( const_iterator  pos,
Args &&...  args 
)
inline

◆ is_array()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array ( ) const
inlineconstexprnoexcept

return whether value is an array

This function returns true if and only if the JSON value is an array.

Returns
true if type is array, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_array() for all JSON types.,is_array}

Since
version 1.0.0

Definition at line 19073 of file json.h.

References nlohmann::detail::array.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::at(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::destroy(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace_back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase(), pyjson::from_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_structured(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[](), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap().

◆ is_binary()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary ( ) const
inlineconstexprnoexcept

◆ is_boolean()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_boolean ( ) const
inlineconstexprnoexcept

return whether value is a boolean

This function returns true if and only if the JSON value is a boolean.

Returns
true if type is boolean, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_boolean() for all JSON types.,is_boolean}

Since
version 1.0.0

Definition at line 18914 of file json.h.

References nlohmann::detail::boolean.

Referenced by pyjson::from_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_primitive().

◆ is_discarded()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_discarded ( ) const
inlineconstexprnoexcept

return whether value is discarded

This function returns true if and only if the JSON value was discarded during parsing with a callback function (see parser_callback_t).

Note
This function will always be false for JSON values after parsing. That is, discarded values can only occur during parsing, but will be removed when inside a structured value or replaced by null in other cases.
Returns
true if type is discarded, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_discarded() for all JSON types.,is_discarded}

Since
version 1.0.0

Definition at line 19144 of file json.h.

References nlohmann::detail::discarded.

◆ is_null()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null ( ) const
inlineconstexprnoexcept

return whether value is null

This function returns true if and only if the JSON value is null.

Returns
true if type is null, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_null() for all JSON types.,is_null}

Since
version 1.0.0

Definition at line 18892 of file json.h.

References nlohmann::detail::null.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace_back(), pyjson::from_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_primitive(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[](), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update().

◆ is_number()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number ( ) const
inlineconstexprnoexcept

return whether value is a number

This function returns true if and only if the JSON value is a number. This includes both integer (signed and unsigned) and floating-point values.

Returns
true if type is number (regardless whether integer, unsigned integer or floating-type), false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_number() for all JSON types.,is_number}

See also
is_number_integer() – check if value is an integer or unsigned integer number
is_number_unsigned() – check if value is an unsigned integer number
is_number_float() – check if value is a floating-point number
Since
version 1.0.0

Definition at line 18944 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number_float(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number_integer().

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_primitive().

◆ is_number_float()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number_float ( ) const
inlineconstexprnoexcept

return whether value is a floating-point number

This function returns true if and only if the JSON value is a floating-point number. This excludes signed and unsigned integer values.

Returns
true if type is a floating-point number, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_number_float() for all JSON types.,is_number_float}

See also
is_number() – check if value is number
is_number_integer() – check if value is an integer number
is_number_unsigned() – check if value is an unsigned integer number
Since
version 1.0.0

Definition at line 19029 of file json.h.

References nlohmann::detail::number_float.

Referenced by pyjson::from_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number().

◆ is_number_integer()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number_integer ( ) const
inlineconstexprnoexcept

return whether value is an integer number

This function returns true if and only if the JSON value is a signed or unsigned integer number. This excludes floating-point values.

Returns
true if type is an integer or unsigned integer number, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_number_integer() for all JSON types.,is_number_integer}

See also
is_number() – check if value is a number
is_number_unsigned() – check if value is an unsigned integer number
is_number_float() – check if value is a floating-point number
Since
version 1.0.0

Definition at line 18973 of file json.h.

References nlohmann::detail::number_integer, and nlohmann::detail::number_unsigned.

Referenced by pyjson::from_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number().

◆ is_number_unsigned()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number_unsigned ( ) const
inlineconstexprnoexcept

return whether value is an unsigned integer number

This function returns true if and only if the JSON value is an unsigned integer number. This excludes floating-point and signed integer values.

Returns
true if type is an unsigned integer number, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_number_unsigned() for all JSON types.,is_number_unsigned}

See also
is_number() – check if value is a number
is_number_integer() – check if value is an integer or unsigned integer number
is_number_float() – check if value is a floating-point number
Since
version 2.0.0

Definition at line 19001 of file json.h.

References nlohmann::detail::number_unsigned.

Referenced by pyjson::from_json(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr().

◆ is_object()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object ( ) const
inlineconstexprnoexcept

return whether value is an object

This function returns true if and only if the JSON value is an object.

Returns
true if type is object, false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_object() for all JSON types.,is_object}

Since
version 1.0.0

Definition at line 19051 of file json.h.

References nlohmann::detail::object.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::at(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::contains(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::count(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::destroy(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_structured(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[](), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value().

◆ is_primitive()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_primitive ( ) const
inlineconstexprnoexcept

return whether type is primitive

This function returns true if and only if the JSON type is primitive (string, number, boolean, or null).

Returns
true if type is primitive (string, number, boolean, or null), false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_primitive() for all JSON types.,is_primitive}

See also
is_structured() – returns whether JSON value is structured
is_null() – returns whether JSON value is null
is_string() – returns whether JSON value is a string
is_boolean() – returns whether JSON value is a boolean
is_number() – returns whether JSON value is a number
is_binary() – returns whether JSON value is a binary array
Since
version 1.0.0

Definition at line 18843 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_boolean(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_number(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_string().

◆ is_string()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_string ( ) const
inlineconstexprnoexcept

◆ is_structured()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_structured ( ) const
inlineconstexprnoexcept

return whether type is structured

This function returns true if and only if the JSON type is structured (array or object).

Returns
true if type is structured (array or object), false otherwise.

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies is_structured() for all JSON types.,is_structured}

See also
is_primitive() – returns whether value is primitive
is_array() – returns whether value is an array
is_object() – returns whether value is an object
Since
version 1.0.0

Definition at line 18870 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object().

◆ items() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iteration_proxy<const_iterator> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::items ( ) const
inlinenoexcept

helper 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.

For loop without items() function:

for (auto it = j_object.begin(); it != j_object.end(); ++it)
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}

Range-based for loop without items() function:

for (auto it : j_object)
{
// "it" is of type json::reference and has no key() member
std::cout << "value: " << it << '\n';
}

Range-based for loop with items() function:

for (auto& el : j_object.items())
{
std::cout << "key: " << el.key() << ", value:" << el.value() << '\n';
}

The items() function also allows to use structured bindings (C++17):

for (auto& [key, val] : j_object.items())
{
std::cout << "key: " << key << ", value:" << val << '\n';
}
@ key
the parser read a key of a value in an object
Note
When iterating over an array, key() will return the index of the element as string (see example). For primitive types (e.g., numbers), key() returns an empty string.
Warning
Using items() on temporary objects is dangerous. Make sure the object's lifetime exeeds the iteration. See https://github.com/nlohmann/json/issues/2040 for more information.
Returns
iteration proxy object wrapping ref with an interface to use in range-based for loops

@liveexample{The following code shows how the function is used.,items}

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Constant.

Since
version 3.1.0, structured bindings support since 3.5.0.

Definition at line 21364 of file json.h.

◆ items() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
iteration_proxy<iterator> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::items ( )
inlinenoexcept

helper 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.

For loop without items() function:

for (auto it = j_object.begin(); it != j_object.end(); ++it)
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}

Range-based for loop without items() function:

for (auto it : j_object)
{
// "it" is of type json::reference and has no key() member
std::cout << "value: " << it << '\n';
}

Range-based for loop with items() function:

for (auto& el : j_object.items())
{
std::cout << "key: " << el.key() << ", value:" << el.value() << '\n';
}

The items() function also allows to use structured bindings (C++17):

for (auto& [key, val] : j_object.items())
{
std::cout << "key: " << key << ", value:" << val << '\n';
}
Note
When iterating over an array, key() will return the index of the element as string (see example). For primitive types (e.g., numbers), key() returns an empty string.
Warning
Using items() on temporary objects is dangerous. Make sure the object's lifetime exeeds the iteration. See https://github.com/nlohmann/json/issues/2040 for more information.
Returns
iteration proxy object wrapping ref with an interface to use in range-based for loops

@liveexample{The following code shows how the function is used.,items}

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Constant.

Since
version 3.1.0, structured bindings support since 3.5.0.

Definition at line 21356 of file json.h.

◆ JSON_HEDLEY_DEPRECATED_FOR() [1/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR ( 3.0.  0,
operator<<  std::ostream &, const basic_json & 
)
inline

serialize to stream

Deprecated:
This stream operator is deprecated and will be removed in future 4.0.0 of the library. Please use operator<<(std::ostream&, const basic_json&) instead; that is, replace calls like j >> o; with o << j;.
Since
version 1.0.0; deprecated since version 3.0.0

Definition at line 23067 of file json.h.

◆ JSON_HEDLEY_DEPRECATED_FOR() [2/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR ( 3.1.  0,
items()   
)
inlinenoexcept

Definition at line 21282 of file json.h.

◆ JSON_HEDLEY_DEPRECATED_FOR() [3/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR ( 3.1.  0,
items()   
)
inlinenoexcept

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.

For loop without iterator_wrapper:

for (auto it = j_object.begin(); it != j_object.end(); ++it)
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}

Range-based for loop without iterator proxy:

for (auto it : j_object)
{
// "it" is of type json::reference and has no key() member
std::cout << "value: " << it << '\n';
}

Range-based for loop with iterator proxy:

for (auto it : json::iterator_wrapper(j_object))
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}
Note
When iterating over an array, key() will return the index of the element as string (see example).
Parameters
[in]refreference to a JSON value
Returns
iteration proxy object wrapping ref with an interface to use in range-based for loops

@liveexample{The following code shows how the wrapper is used,iterator_wrapper}

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@complexity Constant.

Note
The name of this function is not yet final and may change in the future.
Deprecated:
This stream operator is deprecated and will be removed in future 4.0.0 of the library. Please use items() instead; that is, replace json::iterator_wrapper(j) with j.items().

Definition at line 21273 of file json.h.

◆ JSON_HEDLEY_DEPRECATED_FOR() [4/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
JSON_HEDLEY_WARN_UNUSED_RESULT nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR ( 3.8.  0,
accept(ptr, ptr+len  
)
inline

◆ JSON_HEDLEY_DEPRECATED_FOR() [5/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename T >
JSON_HEDLEY_WARN_UNUSED_RESULT nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR ( 3.8.  0,
from_cbor(ptr, ptr+len  
) const

◆ JSON_HEDLEY_DEPRECATED_FOR() [6/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
JSON_HEDLEY_WARN_UNUSED_RESULT nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR ( 3.8.  0,
parse(ptr, ptr+len  
)
inline

◆ JSON_HEDLEY_NON_NULL() [1/5]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename T >
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL ( ) 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.

Warning
If the element with key key does not exist, the behavior is undefined.
Parameters
[in]keykey of the element to access
Returns
const reference to the element at key key
Precondition
The element with key key must exist. This precondition is enforced with an assertion.
Exceptions
type_error.305if the JSON value is not an object; in that case, using the [] operator with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be read using the [] operator.,operatorarray__key_type_const}

See also
at(const typename object_t::key_type&) for access by reference with range checking
value() for access by value with a default value
Since
version 1.1.0

Definition at line 20212 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::detail::JSON_ASSERT(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ JSON_HEDLEY_NON_NULL() [2/5]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename T >
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL ( )
inline

access specified object element

Returns a reference to the element at with specified key key.

Note
If key is not found in the object, then it is silently added to the object and filled with a null value to make key a valid reference. In case the value was null before, it is converted to an object.
Parameters
[in]keykey of the element to access
Returns
reference to the element at key key
Exceptions
type_error.305if the JSON value is not an object or null; in that cases, using the [] operator with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be read and written using the [] operator.,operatorarray__key_type}

See also
at(const typename object_t::key_type&) for access by reference with range checking
value() for access by value with a default value
Since
version 1.1.0

Definition at line 20161 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ JSON_HEDLEY_NON_NULL() [3/5]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType , typename SAX >
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL ( ) &&

generate SAX events

The SAX event lister must follow the interface of json_sax.

This function reads from a compatible input. Examples are:

  • an std::istream object
  • a FILE pointer
  • a C-style array of characters
  • a pointer to a null-terminated string of single byte characters
  • an object obj for which begin(obj) and end(obj) produces a valid pair of iterators.
Parameters
[in]iinput to read from
[in,out]saxSAX event listener
[in]formatthe format to parse (JSON, CBOR, MessagePack, or UBJSON)
[in]strictwhether the input has to be consumed completely
[in]ignore_commentswhether comments should be ignored and treated like whitespace (true) or yield a parse error (true); (optional, false by default); only applies to the JSON file format.
Returns
return value of the last processed SAX event
Exceptions
parse_error.101if a parse error occurs; example: ""unexpected end of input; expected string literal""
parse_error.102if to_unicode fails or surrogate error
parse_error.103if to_unicode fails

@complexity Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the SAX consumer sax has a super-linear complexity.

Note
A UTF-8 byte order mark is silently ignored.

@liveexample{The example below demonstrates the sax_parse() function reading from string and processing the events with a user-defined SAX event consumer.,sax_parse}

Since
version 3.2.0

◆ JSON_HEDLEY_NON_NULL() [4/5]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool class SAX nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL ( )

◆ JSON_HEDLEY_NON_NULL() [5/5]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL ( ) const &

overload for a default value of type const char*

◆ max_size()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::max_size ( ) const
inlinenoexcept

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. std::distance(begin(), end()) for the JSON value.

Returns
The return value depends on the different types and is defined as follows:
Value type return value
null 0 (same as size())
boolean 1 (same as size())
string 1 (same as size())
number 1 (same as size())
binary 1 (same as size())
object result of function object_t::max_size()
array result of function array_t::max_size()

@liveexample{The following code calls max_size() on the different value types. Note the output is implementation specific.,max_size}

@complexity Constant, as long as array_t and object_t satisfy the Container concept; that is, their max_size() functions have constant complexity.

@iterators No changes.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of returning b.size() where b is the largest possible JSON value.
See also
size() – returns the number of elements
Since
version 1.0.0

Definition at line 21565 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::size().

◆ meta()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::meta ( )
inlinestatic

returns version information on the library

This function returns a JSON object with information about the library, including the version number and information on the platform and compiler.

Returns
JSON object holding version information
key description
compiler Information on the used compiler. It is an object with the following keys: c++ (the used C++ standard), family (the compiler family; possible values are clang, icc, gcc, ilecpp, msvc, pgcpp, sunpro, and unknown), and version (the compiler version).
copyright The copyright line for the library as string.
name The name of the library as string.
platform The used platform as string. Possible values are win32, linux, apple, unix, and unknown.
url The URL of the project as string.
version The version of the library. It is an object with the following keys: major, minor, and patch as defined by Semantic Versioning, and string (the version string).

@liveexample{The following code shows an example output of the meta() function.,meta}

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@complexity Constant.

Since
2.1.0

Definition at line 16831 of file json.h.

References nlohmann::to_string().

◆ object()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::object ( initializer_list_t  init = {})
inlinestatic

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.

Note
This function is only added for symmetry reasons. In contrast to the related function array(initializer_list_t), there are no cases which can only be expressed by this function. That is, any initializer list init can also be passed to the initializer list constructor basic_json(initializer_list_t, bool, value_t).
Parameters
[in]initinitializer list to create an object from (optional)
Returns
JSON object value
Exceptions
type_error.301if init is not a list of pairs whose first elements are strings. In this case, no object can be created. When such a value is passed to basic_json(initializer_list_t, bool, value_t), an array would have been created from the passed initializer list init. See example below.

@complexity Linear in the size of init.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

@liveexample{The following code shows an example for the object function.,object}

See also
basic_json(initializer_list_t, bool, value_t)create a JSON value from an initializer list
array(initializer_list_t)create a JSON array value from an initializer list
Since
version 1.0.0

Definition at line 18314 of file json.h.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::create(), and pyjson::to_json().

◆ operator value_t()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator value_t ( ) const
inlineconstexprnoexcept

return the type of the JSON value (implicit)

Implicitly return the type of the JSON value as a value from the value_t enumeration.

Returns
the type of the JSON value

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies the value_t operator for all JSON types.,operator__value_t}

See also
type() – return the type of the JSON value (explicit)
type_name() – return the type as string
Since
version 1.0.0

Definition at line 19170 of file json.h.

◆ operator ValueType()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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#if defined(JSON_HAS_CPP_17) &&(defined(__GNUC__)||(defined(_MSC_VER) &&_MSC_VER >=1910 &&_MSC_VER<=1914)) &&!std::is_same< ValueType, typename std::string_view >::value#endif &&detail::is_detected< detail::get_template_function, const basic_json_t &, ValueType >::value, int >::type = 0>
JSON_EXPLICIT nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Template Parameters
ValueTypenon-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.
Returns
copy of the JSON value, converted to type ValueType
Exceptions
type_error.302in case passed type ValueType is incompatible to the JSON value type (e.g., the JSON value is of type boolean, but a string is requested); see example below

@complexity Linear in the size of the JSON value.

@liveexample{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}

Since
version 1.0.0

Definition at line 19720 of file json.h.

◆ operator+=() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator+= ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &&  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.

Parameters
[in]valthe value to add to the JSON array
Exceptions
type_error.308when called on a type other than JSON array or null; example: "cannot use push_back() with number"

@complexity Amortized constant.

@liveexample{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}

Since
version 1.0.0

Definition at line 21738 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back().

◆ operator+=() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator+= ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  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.

Parameters
[in]valthe value to add to the JSON array
Exceptions
type_error.308when called on a type other than JSON array or null; example: "cannot use push_back() with number"

@complexity Amortized constant.

@liveexample{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}

Since
version 1.0.0

Definition at line 21772 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back().

◆ operator+=() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]valthe value to add to the JSON object
Exceptions
type_error.308when called on a type other than JSON object or null; example: "cannot use push_back() with number"

@complexity Logarithmic in the size of the container, O(log(size())).

@liveexample{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}

Since
version 1.0.0

Definition at line 21822 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back().

◆ operator+=() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator+= ( initializer_list_t  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&&).

Parameters
[in]initan initializer list

@complexity Linear in the size of the initializer list init.

Note
This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.

@liveexample{The example shows how initializer lists are treated as objects when possible.,push_back__initializer_list}

Definition at line 21871 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back().

◆ operator=()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
basic_json& nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator= ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >  other)
inlinenoexcept

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.

Parameters
[in]othervalue to copy from

@complexity Linear.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is linear.

@liveexample{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}

Since
version 1.0.0

Definition at line 18662 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap().

◆ operator[]() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[] ( const typename object_t::key_type &  key)
inline

access specified object element

Returns a reference to the element at with specified key key.

Note
If key is not found in the object, then it is silently added to the object and filled with a null value to make key a valid reference. In case the value was null before, it is converted to an object.
Parameters
[in]keykey of the element to access
Returns
reference to the element at key key
Exceptions
type_error.305if the JSON value is not an object or null; in that cases, using the [] operator with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be read and written using the [] operator.,operatorarray__key_type}

See also
at(const typename object_t::key_type&) for access by reference with range checking
value() for access by value with a default value
Since
version 1.0.0

Definition at line 20072 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ operator[]() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Warning
If the element with key key does not exist, the behavior is undefined.
Parameters
[in]keykey of the element to access
Returns
const reference to the element at key key
Precondition
The element with key key must exist. This precondition is enforced with an assertion.
Exceptions
type_error.305if the JSON value is not an object; in that case, using the [] operator with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be read using the [] operator.,operatorarray__key_type_const}

See also
at(const typename object_t::key_type&) for access by reference with range checking
value() for access by value with a default value
Since
version 1.0.0

Definition at line 20121 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::detail::JSON_ASSERT(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ operator[]() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[] ( size_type  idx)
inline

access specified array element

Returns a reference to the element at specified location idx.

Note
If idx is beyond the range of the array (i.e., idx >= size()), then the array is silently filled up with null values to make idx a valid reference to the last stored element.
Parameters
[in]idxindex of the element to access
Returns
reference to the element at index idx
Exceptions
type_error.305if the JSON value is not an array or null; in that cases, using the [] operator with an index makes no sense.

@complexity Constant if idx is in the range of the array. Otherwise linear in idx - size().

@liveexample{The example below shows how array elements can be read and written using [] operator. Note the addition of null values.,operatorarray__size_type}

Since
version 1.0.0

Definition at line 19988 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ operator[]() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[] ( size_type  idx) const
inline

access specified array element

Returns a const reference to the element at specified location idx.

Parameters
[in]idxindex of the element to access
Returns
const reference to the element at index idx
Exceptions
type_error.305if the JSON value is not an array; in that case, using the [] operator with an index makes no sense.

@complexity Constant.

@liveexample{The example below shows how array elements can be read using the [] operator.,operatorarray__size_type_const}

Since
version 1.0.0

Definition at line 20034 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ parse() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputType >
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parse ( InputType &&  i,
const parser_callback_t  cb = nullptr,
const bool  allow_exceptions = true,
const bool  ignore_comments = false 
)
inlinestatic

deserialize from a compatible input

Template Parameters
InputTypeA compatible input, for instance
  • an std::istream object
  • a FILE pointer
  • a C-style array of characters
  • a pointer to a null-terminated string of single byte characters
  • an object obj for which begin(obj) and end(obj) produces a valid pair of iterators.
Parameters
[in]iinput to read from
[in]cba parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)
[in]allow_exceptionswhether to throw exceptions in case of a parse error (optional, true by default)
[in]ignore_commentswhether comments should be ignored and treated like whitespace (true) or yield a parse error (true); (optional, false by default)
Returns
deserialized JSON value; in case of a parse error and allow_exceptions set to false, the return value will be value_t::discarded.
Exceptions
parse_error.101if a parse error occurs; example: ""unexpected end of input; expected string literal""
parse_error.102if to_unicode fails or surrogate error
parse_error.103if to_unicode fails

@complexity 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 or reading from the input i has a super-linear complexity.

Note
A UTF-8 byte order mark is silently ignored.

@liveexample{The example below demonstrates the parse() function reading from an array.,parse__array__parser_callback_t}

@liveexample{The example below demonstrates the parse() function with and without callback function.,parse__string__parser_callback_t}

@liveexample{The example below demonstrates the parse() function with and without callback function.,parse__istream__parser_callback_t}

@liveexample{The example below demonstrates the parse() function reading from a contiguous container.,parse__contiguouscontainer__parser_callback_t}

Since
version 2.0.3 (contiguous containers); version 3.9.0 allowed to ignore comments.

Definition at line 23136 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::allow_exceptions, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::ignore_comments, nlohmann::detail::input_adapter(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parser().

Referenced by umbridge::HTTPModel::ApplyHessian(), umbridge::HTTPModel::ApplyJacobian(), umbridge::HTTPModel::Evaluate(), umbridge::HTTPModel::GetInputSizes(), umbridge::HTTPModel::GetOutputSizes(), umbridge::HTTPModel::Gradient(), umbridge::HTTPModel::HTTPModel(), JSON_HEDLEY_NON_NULL(), and umbridge::serveModels().

◆ parse() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename IteratorType >
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parse ( IteratorType  first,
IteratorType  last,
const parser_callback_t  cb = nullptr,
const bool  allow_exceptions = true,
const bool  ignore_comments = false 
)
inlinestatic

deserialize from a pair of character iterators

The value_type of the iterator must be a integral type with size of 1, 2 or 4 bytes, which will be interpreted respectively as UTF-8, UTF-16 and UTF-32.

Parameters
[in]firstiterator to start of character range
[in]lastiterator to end of character range
[in]cba parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)
[in]allow_exceptionswhether to throw exceptions in case of a parse error (optional, true by default)
[in]ignore_commentswhether comments should be ignored and treated like whitespace (true) or yield a parse error (true); (optional, false by default)
Returns
deserialized JSON value; in case of a parse error and allow_exceptions set to false, the return value will be value_t::discarded.
Exceptions
parse_error.101if a parse error occurs; example: ""unexpected end of input; expected string literal""
parse_error.102if to_unicode fails or surrogate error
parse_error.103if to_unicode fails

Definition at line 23174 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::allow_exceptions, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::ignore_comments, nlohmann::detail::input_adapter(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parser().

◆ parser()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename InputAdapterType >
static ::nlohmann::detail::parser<basic_json, InputAdapterType> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parser ( InputAdapterType  adapter,
detail::parser_callback_t< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > >  cb = nullptr,
const bool  allow_exceptions = true,
const bool  ignore_comments = false 
)
inlineprivate

◆ push_back() [1/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &&  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.

Parameters
[in]valthe value to add to the JSON array
Exceptions
type_error.308when called on a type other than JSON array or null; example: "cannot use push_back() with number"

@complexity Amortized constant.

@liveexample{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}

Since
version 1.0.0

Definition at line 21713 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator+=(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back(), and umbridge::serveModels().

◆ push_back() [2/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  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.

Parameters
[in]valthe value to add to the JSON array
Exceptions
type_error.308when called on a type other than JSON array or null; example: "cannot use push_back() with number"

@complexity Amortized constant.

@liveexample{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}

Since
version 1.0.0

Definition at line 21748 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ push_back() [3/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in]valthe value to add to the JSON object
Exceptions
type_error.308when called on a type other than JSON object or null; example: "cannot use push_back() with number"

@complexity Logarithmic in the size of the container, O(log(size())).

@liveexample{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}

Since
version 1.0.0

Definition at line 21798 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ push_back() [4/4]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back ( initializer_list_t  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&&).

Parameters
[in]initan initializer list

@complexity Linear in the size of the initializer list init.

Note
This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.

@liveexample{The example shows how initializer lists are treated as objects when possible.,push_back__initializer_list}

Definition at line 21853 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back().

◆ rbegin() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rbegin ( ) const
inlinenoexcept

returns a const reverse iterator to the last element

Returns a const iterator to the reverse-beginning; that is, the last element.

Illustration from cppreference.com

@complexity Constant.

@requirement This function helps basic_json satisfying the ReversibleContainer requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).rbegin().

@liveexample{The following code shows an example for crbegin().,crbegin}

See also
rbegin() – returns a reverse iterator to the beginning
rend() – returns a reverse iterator to the end
crend() – returns a const reverse iterator to the end
Since
version 1.0.0

Definition at line 21115 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::crbegin().

◆ rbegin() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rbegin ( )
inlinenoexcept

returns an iterator to the reverse-beginning

Returns an iterator to the reverse-beginning; that is, the last element.

Illustration from cppreference.com

@complexity Constant.

@requirement This function helps basic_json satisfying the ReversibleContainer requirements:

  • The complexity is constant.
  • Has the semantics of reverse_iterator(end()).

@liveexample{The following code shows an example for rbegin().,rbegin}

See also
crbegin() – returns a const reverse iterator to the beginning
rend() – returns a reverse iterator to the end
crend() – returns a const reverse iterator to the end
Since
version 1.0.0

Definition at line 21107 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end().

◆ rend() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const_reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rend ( ) const
inlinenoexcept

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.

Illustration from cppreference.com

@complexity Constant.

@requirement This function helps basic_json satisfying the ReversibleContainer requirements:

  • The complexity is constant.
  • Has the semantics of const_cast<const basic_json&>(*this).rend().

@liveexample{The following code shows an example for crend().,crend}

See also
rend() – returns a reverse iterator to the end
rbegin() – returns a reverse iterator to the beginning
crbegin() – returns a const reverse iterator to the beginning
Since
version 1.0.0

Definition at line 21152 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::crend().

◆ rend() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
reverse_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::rend ( )
inlinenoexcept

returns an iterator to the reverse-end

Returns an iterator to the reverse-end; that is, one before the first element.

Illustration from cppreference.com

@complexity Constant.

@requirement This function helps basic_json satisfying the ReversibleContainer requirements:

  • The complexity is constant.
  • Has the semantics of reverse_iterator(begin()).

@liveexample{The following code shows an example for rend().,rend}

See also
crend() – returns a const reverse iterator to the end
rbegin() – returns a reverse iterator to the beginning
crbegin() – returns a const reverse iterator to the beginning
Since
version 1.0.0

Definition at line 21144 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::begin().

◆ size()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::size ( ) const
inlinenoexcept

returns the number of elements

Returns the number of elements in a JSON value.

Returns
The return value depends on the different types and is defined as follows:
Value type return value
null 0
boolean 1
string 1
number 1
binary 1
object result of function object_t::size()
array result of function array_t::size()

@liveexample{The following code calls size() on the different value types.,size}

@complexity Constant, as long as array_t and object_t satisfy the Container concept; that is, their size() functions have constant complexity.

@iterators No changes.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

Note
This function does not return the length of a string stored as JSON value - it returns the number of elements in the JSON value which is 1 in the case of a string.

@requirement This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of std::distance(begin(), end()).
See also
empty() – checks whether the container is empty
max_size() – returns the maximal number of elements
Since
version 1.0.0

Definition at line 21494 of file json.h.

References nlohmann::detail::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::null, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase(), umbridge::HTTPModel::Evaluate(), pyjson::from_json(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::max_size().

◆ swap() [1/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in,out]otherarray to exchange the contents with
Exceptions
type_error.310when JSON value is not an array; example: "cannot use swap() with string"

@complexity Constant.

@liveexample{The example below shows how arrays can be swapped with swap().,swap__array_t}

Since
version 1.0.0

Definition at line 22419 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::array, nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_array(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ swap() [2/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap ( binary_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.

Parameters
[in,out]otherbinary to exchange the contents with
Exceptions
type_error.310when JSON value is not a string; example: "cannot use swap() with boolean"

@complexity Constant.

@liveexample{The example below shows how strings can be swapped with swap().,swap__binary_t}

Since
version 3.8.0

Definition at line 22518 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::binary, nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_binary(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

◆ swap() [3/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in,out]otherobject to exchange the contents with
Exceptions
type_error.310when JSON value is not an object; example: "cannot use swap() with string"

@complexity Constant.

@liveexample{The example below shows how objects can be swapped with swap().,swap__object_t}

Since
version 1.0.0

Definition at line 22452 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ swap() [4/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap ( reference  other)
inlinenoexcept

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.

Parameters
[in,out]otherJSON value to exchange the contents with

@complexity Constant.

@liveexample{The example below shows how JSON values can be swapped with swap().,swap__reference}

Since
version 1.0.0

Definition at line 22359 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator=().

◆ swap() [5/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::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.

Parameters
[in,out]otherstring to exchange the contents with
Exceptions
type_error.310when JSON value is not a string; example: "cannot use swap() with boolean"

@complexity Constant.

@liveexample{The example below shows how strings can be swapped with swap().,swap__string_t}

Since
version 1.0.0

Definition at line 22485 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_string(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::string.

◆ swap() [6/6]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap ( typename binary_t::container_type other)
inline

◆ to_bson() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static std::vector<uint8_t> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_bson ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j)
inlinestatic

Serializes the given JSON object j to BSON and returns a vector containing the corresponding BSON-representation.

BSON (Binary JSON) is a binary format in which zero or more ordered key/value pairs are stored as a single entity (a so-called document).

The library uses the following mapping from JSON values types to BSON types:

JSON value type value/range BSON type marker
null null null 0x0A
boolean true, false boolean 0x08
number_integer -9223372036854775808..-2147483649 int64 0x12
number_integer -2147483648..2147483647 int32 0x10
number_integer 2147483648..9223372036854775807 int64 0x12
number_unsigned 0..2147483647 int32 0x10
number_unsigned 2147483648..9223372036854775807 int64 0x12
number_unsigned 9223372036854775808..18446744073709551615
number_float any value double 0x01
string any value string 0x02
array any value document 0x04
object any value document 0x03
binary any value binary 0x05
Warning
The mapping is incomplete, since only JSON-objects (and things contained therein) can be serialized to BSON. Also, integers larger than 9223372036854775807 cannot be serialized to BSON, and the keys may not contain U+0000, since they are serialized a zero-terminated c-strings.
Exceptions
out_of_range.407if j.is_number_unsigned() && j.get<std::uint64_t>() > 9223372036854775807
out_of_range.409if a key in j contains a NULL (U+0000)
type_error.317if !j.is_object()
Precondition
The input j is required to be an object: j.is_object() == true.
Note
Any BSON output created via to_bson can be successfully parsed by from_bson.
Parameters
[in]jJSON value to serialize
Returns
BSON serialization as byte vector

@complexity Linear in the size of the JSON value j.

@liveexample{The example shows the serialization of a JSON value to a byte vector in BSON format.,to_bson}

See also
http://bsonspec.org/spec.html
from_bson(detail::input_adapter&&, const bool strict) for the analogous deserialization
to_ubjson(const basic_json&, const bool, const bool) for the related UBJSON format
to_cbor(const basic_json&) for the related CBOR format
to_msgpack(const basic_json&) for the related MessagePack format

Definition at line 23827 of file json.h.

◆ to_bson() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_bson ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< char >  o 
)
inlinestatic

Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the given output_adapter o.

Parameters
jThe JSON object to convert to BSON.
oThe output adapter that receives the binary BSON representation.
Precondition
The input j shall be an object: j.is_object() == true
See also
to_bson(const basic_json&)

Definition at line 23850 of file json.h.

References nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson().

◆ to_bson() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_bson ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< uint8_t >  o 
)
inlinestatic

Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the given output_adapter o.

Parameters
jThe JSON object to convert to BSON.
oThe output adapter that receives the binary BSON representation.
Precondition
The input j shall be an object: j.is_object() == true
See also
to_bson(const basic_json&)

Definition at line 23842 of file json.h.

References nlohmann::detail::binary_writer< BasicJsonType, CharType >::write_bson().

◆ to_cbor() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static std::vector<uint8_t> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_cbor ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j)
inlinestatic

create a CBOR serialization of a given JSON value

Serializes a given JSON value j to a byte vector using the CBOR (Concise Binary Object Representation) serialization format. CBOR is a binary serialization format which aims to be more compact than JSON itself, yet more efficient to parse.

The library uses the following mapping from JSON values types to CBOR types according to the CBOR specification (RFC 7049):

JSON value type value/range CBOR type first byte
null null Null 0xF6
boolean true True 0xF5
boolean false False 0xF4
number_integer -9223372036854775808..-2147483649 Negative integer (8 bytes follow) 0x3B
number_integer -2147483648..-32769 Negative integer (4 bytes follow) 0x3A
number_integer -32768..-129 Negative integer (2 bytes follow) 0x39
number_integer -128..-25 Negative integer (1 byte follow) 0x38
number_integer -24..-1 Negative integer 0x20..0x37
number_integer 0..23 Integer 0x00..0x17
number_integer 24..255 Unsigned integer (1 byte follow) 0x18
number_integer 256..65535 Unsigned integer (2 bytes follow) 0x19
number_integer 65536..4294967295 Unsigned integer (4 bytes follow) 0x1A
number_integer 4294967296..18446744073709551615 Unsigned integer (8 bytes follow) 0x1B
number_unsigned 0..23 Integer 0x00..0x17
number_unsigned 24..255 Unsigned integer (1 byte follow) 0x18
number_unsigned 256..65535 Unsigned integer (2 bytes follow) 0x19
number_unsigned 65536..4294967295 Unsigned integer (4 bytes follow) 0x1A
number_unsigned 4294967296..18446744073709551615 Unsigned integer (8 bytes follow) 0x1B
number_float any value representable by a float Single-Precision Float 0xFA
number_float any value NOT representable by a float Double-Precision Float 0xFB
string length: 0..23 UTF-8 string 0x60..0x77
string length: 23..255 UTF-8 string (1 byte follow) 0x78
string length: 256..65535 UTF-8 string (2 bytes follow) 0x79
string length: 65536..4294967295 UTF-8 string (4 bytes follow) 0x7A
string length: 4294967296..18446744073709551615 UTF-8 string (8 bytes follow) 0x7B
array size: 0..23 array 0x80..0x97
array size: 23..255 array (1 byte follow) 0x98
array size: 256..65535 array (2 bytes follow) 0x99
array size: 65536..4294967295 array (4 bytes follow) 0x9A
array size: 4294967296..18446744073709551615 array (8 bytes follow) 0x9B
object size: 0..23 map 0xA0..0xB7
object size: 23..255 map (1 byte follow) 0xB8
object size: 256..65535 map (2 bytes follow) 0xB9
object size: 65536..4294967295 map (4 bytes follow) 0xBA
object size: 4294967296..18446744073709551615 map (8 bytes follow) 0xBB
binary size: 0..23 byte string 0x40..0x57
binary size: 23..255 byte string (1 byte follow) 0x58
binary size: 256..65535 byte string (2 bytes follow) 0x59
binary size: 65536..4294967295 byte string (4 bytes follow) 0x5A
binary size: 4294967296..18446744073709551615 byte string (8 bytes follow) 0x5B
Note
The mapping is complete in the sense that any JSON value type can be converted to a CBOR value.
If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the dump() function which serializes NaN or Infinity to null.
The following CBOR types are not used in the conversion:
  • UTF-8 strings terminated by "break" (0x7F)
  • arrays terminated by "break" (0x9F)
  • maps terminated by "break" (0xBF)
  • byte strings terminated by "break" (0x5F)
  • date/time (0xC0..0xC1)
  • bignum (0xC2..0xC3)
  • decimal fraction (0xC4)
  • bigfloat (0xC5)
  • expected conversions (0xD5..0xD7)
  • simple values (0xE0..0xF3, 0xF8)
  • undefined (0xF7)
  • half-precision floats (0xF9)
  • break (0xFF)
Parameters
[in]jJSON value to serialize
Returns
CBOR serialization as byte vector

@complexity Linear in the size of the JSON value j.

@liveexample{The example shows the serialization of a JSON value to a byte vector in CBOR format.,to_cbor}

See also
http://cbor.io
from_cbor(detail::input_adapter&&, const bool, const bool, const cbor_tag_handler_t) for the analogous deserialization
to_msgpack(const basic_json&) for the related MessagePack format
to_ubjson(const basic_json&, const bool, const bool) for the related UBJSON format
Since
version 2.0.9; compact representation of floating-point numbers since version 3.8.0

Definition at line 23551 of file json.h.

◆ to_cbor() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_cbor ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< char >  o 
)
inlinestatic

◆ to_cbor() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_cbor ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< uint8_t >  o 
)
inlinestatic

◆ to_msgpack() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static std::vector<uint8_t> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_msgpack ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j)
inlinestatic

create a MessagePack serialization of a given JSON value

Serializes a given JSON value j to a byte vector using the MessagePack serialization format. MessagePack is a binary serialization format which aims to be more compact than JSON itself, yet more efficient to parse.

The library uses the following mapping from JSON values types to MessagePack types according to the MessagePack specification:

JSON value type value/range MessagePack type first byte
null null nil 0xC0
boolean true true 0xC3
boolean false false 0xC2
number_integer -9223372036854775808..-2147483649 int64 0xD3
number_integer -2147483648..-32769 int32 0xD2
number_integer -32768..-129 int16 0xD1
number_integer -128..-33 int8 0xD0
number_integer -32..-1 negative fixint 0xE0..0xFF
number_integer 0..127 positive fixint 0x00..0x7F
number_integer 128..255 uint 8 0xCC
number_integer 256..65535 uint 16 0xCD
number_integer 65536..4294967295 uint 32 0xCE
number_integer 4294967296..18446744073709551615 uint 64 0xCF
number_unsigned 0..127 positive fixint 0x00..0x7F
number_unsigned 128..255 uint 8 0xCC
number_unsigned 256..65535 uint 16 0xCD
number_unsigned 65536..4294967295 uint 32 0xCE
number_unsigned 4294967296..18446744073709551615 uint 64 0xCF
number_float any value representable by a float float 32 0xCA
number_float any value NOT representable by a float float 64 0xCB
string length: 0..31 fixstr 0xA0..0xBF
string length: 32..255 str 8 0xD9
string length: 256..65535 str 16 0xDA
string length: 65536..4294967295 str 32 0xDB
array size: 0..15 fixarray 0x90..0x9F
array size: 16..65535 array 16 0xDC
array size: 65536..4294967295 array 32 0xDD
object size: 0..15 fix map 0x80..0x8F
object size: 16..65535 map 16 0xDE
object size: 65536..4294967295 map 32 0xDF
binary size: 0..255 bin 8 0xC4
binary size: 256..65535 bin 16 0xC5
binary size: 65536..4294967295 bin 32 0xC6
Note
The mapping is complete in the sense that any JSON value type can be converted to a MessagePack value.
The following values can not be converted to a MessagePack value:
  • strings with more than 4294967295 bytes
  • byte strings with more than 4294967295 bytes
  • arrays with more than 4294967295 elements
  • objects with more than 4294967295 elements
Any MessagePack output created to_msgpack can be successfully parsed by from_msgpack.
If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the dump() function which serializes NaN or Infinity to null.
Parameters
[in]jJSON value to serialize
Returns
MessagePack serialization as byte vector

@complexity Linear in the size of the JSON value j.

@liveexample{The example shows the serialization of a JSON value to a byte vector in MessagePack format.,to_msgpack}

See also
http://msgpack.org
from_msgpack for the analogous deserialization
to_cbor(const basic_json& for the related CBOR format
to_ubjson(const basic_json&, const bool, const bool) for the related UBJSON format
Since
version 2.0.9

Definition at line 23646 of file json.h.

◆ to_msgpack() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_msgpack ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< char >  o 
)
inlinestatic

◆ to_msgpack() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_msgpack ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< uint8_t >  o 
)
inlinestatic

◆ to_ubjson() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static std::vector<uint8_t> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_ubjson ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
const bool  use_size = false,
const bool  use_type = false 
)
inlinestatic

create a UBJSON serialization of a given JSON value

Serializes a given JSON value j to a byte vector using the UBJSON (Universal Binary JSON) serialization format. UBJSON aims to be more compact than JSON itself, yet more efficient to parse.

The library uses the following mapping from JSON values types to UBJSON types according to the UBJSON specification:

JSON value type value/range UBJSON type marker
null null null Z
boolean true true T
boolean false false F
number_integer -9223372036854775808..-2147483649 int64 L
number_integer -2147483648..-32769 int32 l
number_integer -32768..-129 int16 I
number_integer -128..127 int8 i
number_integer 128..255 uint8 U
number_integer 256..32767 int16 I
number_integer 32768..2147483647 int32 l
number_integer 2147483648..9223372036854775807 int64 L
number_unsigned 0..127 int8 i
number_unsigned 128..255 uint8 U
number_unsigned 256..32767 int16 I
number_unsigned 32768..2147483647 int32 l
number_unsigned 2147483648..9223372036854775807 int64 L
number_unsigned 2147483649..18446744073709551615 high-precision H
number_float any value float64 D
string with shortest length indicator string S
array see notes on optimized format array [
object see notes on optimized format map {
Note
The mapping is complete in the sense that any JSON value type can be converted to a UBJSON value.
The following values can not be converted to a UBJSON value:
  • strings with more than 9223372036854775807 bytes (theoretical)
The following markers are not used in the conversion:
  • Z: no-op values are not created.
  • C: single-byte strings are serialized with S markers.
Any UBJSON output created to_ubjson can be successfully parsed by from_ubjson.
If NaN or Infinity are stored inside a JSON number, they are serialized properly. This behavior differs from the dump() function which serializes NaN or Infinity to null.
The optimized formats for containers are supported: Parameter use_size adds size information to the beginning of a container and removes the closing marker. Parameter use_type further checks whether all elements of a container have the same type and adds the type marker to the beginning of the container. The use_type parameter must only be used together with use_size = true. Note that use_size = true alone may result in larger representations - the benefit of this parameter is that the receiving side is immediately informed on the number of elements of the container.
If the JSON data contains the binary type, the value stored is a list of integers, as suggested by the UBJSON documentation. In particular, this means that serialization and the deserialization of a JSON containing binary values into UBJSON and back will result in a different JSON object.
Parameters
[in]jJSON value to serialize
[in]use_sizewhether to add size annotations to container types
[in]use_typewhether to add type annotations to container types (must be combined with use_size = true)
Returns
UBJSON serialization as byte vector

@complexity Linear in the size of the JSON value j.

@liveexample{The example shows the serialization of a JSON value to a byte vector in UBJSON format.,to_ubjson}

See also
http://ubjson.org
from_ubjson(detail::input_adapter&&, const bool, const bool) for the analogous deserialization
to_cbor(const basic_json& for the related CBOR format
to_msgpack(const basic_json&) for the related MessagePack format
Since
version 3.1.0

Definition at line 23749 of file json.h.

◆ to_ubjson() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_ubjson ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< char >  o,
const bool  use_size = false,
const bool  use_type = false 
)
inlinestatic

◆ to_ubjson() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
static void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::to_ubjson ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  j,
detail::output_adapter< uint8_t >  o,
const bool  use_size = false,
const bool  use_type = false 
)
inlinestatic

◆ type()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
constexpr value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::type ( ) const
inlineconstexprnoexcept

return the type of the JSON value (explicit)

Return the type of the JSON value as a value from the value_t enumeration.

Returns
the type of the JSON value
Value type return value
null value_t::null
boolean value_t::boolean
string value_t::string
number (integer) value_t::number_integer
number (unsigned integer) value_t::number_unsigned
number (floating-point) value_t::number_float
object value_t::object
array value_t::array
binary value_t::binary
discarded value_t::discarded

@complexity Constant.

@exceptionsafety No-throw guarantee: this member function never throws exceptions.

@liveexample{The following code exemplifies type() for all JSON types.,type}

See also
operator value_t() – return the type of the JSON value (implicit)
type_name() – return the type as string
Since
version 1.0.0

Definition at line 18812 of file json.h.

◆ update() [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update ( const_iterator  first,
const_iterator  last 
)
inline

updates a JSON object from another object, overwriting existing keys

Inserts all values from from range [first, last) and overwrites existing keys.

Parameters
[in]firstbegin of the range of elements to insert
[in]lastend of the range of elements to insert
Exceptions
type_error.312if called on JSON values other than objects; example: "cannot use update() with string"
invalid_iterator.202if iterator first or last does does not point to an object; example: "iterators first and last must point to objects"
invalid_iterator.210if first and last do not belong to the same JSON value; example: "iterators do not fit"

@complexity O(N*log(size() + N)), where N is the number of elements to insert.

@liveexample{The example shows how update() is used__range.,update}

See also
https://docs.python.org/3.6/library/stdtypes.html#dict.update
Since
version 3.0.0

Definition at line 22308 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last, nlohmann::detail::iter_impl< BasicJsonType >::m_object, nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ update() [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update ( const_reference  j)
inline

updates a JSON object from another object, overwriting existing keys

Inserts all values from JSON object j and overwrites existing keys.

Parameters
[in]jJSON object to read values from
Exceptions
type_error.312if called on JSON values other than objects; example: "cannot use update() with string"

@complexity O(N*log(size() + N)), where N is the number of elements to insert.

@liveexample{The example shows how update() is used.,update}

See also
https://docs.python.org/3.6/library/stdtypes.html#dict.update
Since
version 3.0.0

Definition at line 22257 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cbegin(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::cend(), nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_null(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value, nlohmann::detail::object, and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::object.

◆ value() [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<class ValueType , typename std::enable_if< detail::is_getable< basic_json_t, ValueType >::value, int >::type = 0>
ValueType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value ( const json_pointer ptr,
const ValueType &  default_value 
) const
inline

access specified object element via JSON Pointer 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

try {
return at(ptr);
} catch(out_of_range) {
return default_value;
}
detail::out_of_range out_of_range
exception indicating access out of the defined range
Definition: json.h:16747
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.h:19793
Note
Unlike at(const json_pointer&), this function does not throw if the given key key was not found.
Parameters
[in]ptra JSON pointer to the element to access
[in]default_valuethe value to return if ptr found no value
Template Parameters
ValueTypetype 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.
Returns
copy of the element at key key or default_value if key is not found
Exceptions
type_error.302if default_value does not match the type of the value at ptr
type_error.306if the JSON value is not an object; in that case, using value() with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be queried with a default value.,basic_json__value_ptr}

See also
operator[](const json_pointer&) for unchecked access by reference
Since
version 2.0.2

Definition at line 20351 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::json_pointer< BasicJsonType >::get_checked(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object().

◆ value() [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value ( const typename object_t::key_type &  key,
const char *  default_value 
) const
inline

overload for a default value of type const char*

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

try {
return at(key);
} catch(out_of_range) {
return default_value;
}
Note
Unlike at(const typename object_t::key_type&), this function does not throw if the given key key was not found.
Unlike operator[](const typename object_t::key_type& key), this function does not implicitly add an element to the position defined by key. This function is furthermore also applicable to const objects.
Parameters
[in]keykey of the element to access
[in]default_valuethe value to return if key is not found
Template Parameters
ValueTypetype 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.
Returns
copy of the element at key key or default_value if key is not found
Exceptions
type_error.302if default_value does not match the type of the value at key
type_error.306if the JSON value is not an object; in that case, using value() with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be queried with a default value.,basic_json__value}

See also
at(const typename object_t::key_type&) for access by reference with range checking
operator[](const typename object_t::key_type&) for unchecked access by reference
Since
version 1.0.0

Definition at line 20301 of file json.h.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value().

◆ value() [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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 nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value ( const typename object_t::key_type &  key,
const 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

try {
return at(key);
} catch(out_of_range) {
return default_value;
}
Note
Unlike at(const typename object_t::key_type&), this function does not throw if the given key key was not found.
Unlike operator[](const typename object_t::key_type& key), this function does not implicitly add an element to the position defined by key. This function is furthermore also applicable to const objects.
Parameters
[in]keykey of the element to access
[in]default_valuethe value to return if key is not found
Template Parameters
ValueTypetype 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.
Returns
copy of the element at key key or default_value if key is not found
Exceptions
type_error.302if default_value does not match the type of the value at key
type_error.306if the JSON value is not an object; in that case, using value() with a key makes no sense.

@complexity Logarithmic in the size of the container.

@liveexample{The example below shows how object elements can be queried with a default value.,basic_json__value}

See also
at(const typename object_t::key_type&) for access by reference with range checking
operator[](const typename object_t::key_type&) for unchecked access by reference
Since
version 1.0.0

Definition at line 20279 of file json.h.

References nlohmann::detail::type_error::create(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::end(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::is_object().

Referenced by umbridge::HTTPModel::HTTPModel(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::json_value(), umbridge::serveModels(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value().

Friends And Related Function Documentation

◆ ::nlohmann::detail::binary_reader

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType , typename InputType , typename SAX >
friend class ::nlohmann::detail::binary_reader
friend

Definition at line 16671 of file json.h.

◆ ::nlohmann::detail::binary_writer

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType , typename CharType >
friend class ::nlohmann::detail::binary_writer
friend

Definition at line 16669 of file json.h.

◆ ::nlohmann::detail::iter_impl

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType >
friend class ::nlohmann::detail::iter_impl
friend

Definition at line 16667 of file json.h.

◆ ::nlohmann::detail::json_sax_dom_callback_parser

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType >
friend class ::nlohmann::detail::json_sax_dom_callback_parser
friend

Definition at line 16675 of file json.h.

◆ ::nlohmann::detail::json_sax_dom_parser

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType >
friend class ::nlohmann::detail::json_sax_dom_parser
friend

Definition at line 16673 of file json.h.

◆ ::nlohmann::detail::parser

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename BasicJsonType , typename InputType >
friend class ::nlohmann::detail::parser
friend

Definition at line 16664 of file json.h.

◆ detail::external_constructor

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<detail::value_t >
friend struct detail::external_constructor
friend

Definition at line 16660 of file json.h.

◆ operator!= [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator!= ( const ScalarType  lhs,
const_reference  rhs 
)
friend

comparison: not equal

comparison: not equal Compares two JSON values for inequality by calculating not (lhs == rhs).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are not equal

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__notequal}

Since
version 1.0.0

Definition at line 22740 of file json.h.

◆ operator!= [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator!= ( const_reference  lhs,
const ScalarType  rhs 
)
friend

comparison: not equal

comparison: not equal Compares two JSON values for inequality by calculating not (lhs == rhs).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are not equal

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__notequal}

Since
version 1.0.0

Definition at line 22729 of file json.h.

◆ operator!= [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
bool operator!= ( const_reference  lhs,
const_reference  rhs 
)
friend

comparison: not equal

Compares two JSON values for inequality by calculating not (lhs == rhs).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are not equal

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__notequal}

Since
version 1.0.0

Definition at line 22718 of file json.h.

◆ operator< [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator< ( const ScalarType  lhs,
const_reference  rhs 
)
friend

comparison: less than

comparison: less than Compares whether one JSON value lhs is less than another JSON value rhs according to the following rules:

  • If lhs and rhs have the same type, the values are compared using the default < operator.
  • Integer and floating-point numbers are automatically converted before comparison
  • In case lhs and rhs have different types, the values are ignored and the order of the types is considered, see operator<(const value_t, const value_t).
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__less}

Since
version 1.0.0

Definition at line 22861 of file json.h.

◆ operator< [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator< ( const_reference  lhs,
const ScalarType  rhs 
)
friend

comparison: less than

comparison: less than Compares whether one JSON value lhs is less than another JSON value rhs according to the following rules:

  • If lhs and rhs have the same type, the values are compared using the default < operator.
  • Integer and floating-point numbers are automatically converted before comparison
  • In case lhs and rhs have different types, the values are ignored and the order of the types is considered, see operator<(const value_t, const value_t).
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__less}

Since
version 1.0.0

Definition at line 22850 of file json.h.

◆ operator< [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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:

  • If lhs and rhs have the same type, the values are compared using the default < operator.
  • Integer and floating-point numbers are automatically converted before comparison
  • In case lhs and rhs have different types, the values are ignored and the order of the types is considered, see operator<(const value_t, const value_t).
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__less}

Since
version 1.0.0

Definition at line 22771 of file json.h.

◆ operator<<

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
std::ostream& operator<< ( std::ostream &  o,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  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).
  • The indentation character can be controlled with the member variable fill of the output stream o. For instance, the manipulator ‘std::setfill(’\t')` sets indentation to use a tab character rather than the default space character.
Parameters
[in,out]ostream to serialize to
[in]jJSON value to serialize
Returns
the stream o
Exceptions
type_error.316if a string stored inside the JSON value is not UTF-8 encoded

@complexity Linear.

@liveexample{The example below shows the serialization with different parameters to width to adjust the indentation level.,operator_serialize}

Since
version 1.0.0; indentation character added in version 3.0.0

Definition at line 23044 of file json.h.

◆ operator<= [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator<= ( const ScalarType  lhs,
const_reference  rhs 
)
friend

comparison: less than or equal

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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than or equal to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__greater}

Since
version 1.0.0

Definition at line 22907 of file json.h.

◆ operator<= [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator<= ( const_reference  lhs,
const ScalarType  rhs 
)
friend

comparison: less than or equal

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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than or equal to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__greater}

Since
version 1.0.0

Definition at line 22896 of file json.h.

◆ operator<= [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than or equal to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__greater}

Since
version 1.0.0

Definition at line 22885 of file json.h.

◆ operator== [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator== ( const ScalarType  lhs,
const_reference  rhs 
)
friend

comparison: equal

comparison: equal Compares two JSON values for equality according to the following rules:

  • Two JSON values are equal if (1) they are from the same type and (2) their stored values are the same according to their respective operator==.
  • Integer and floating-point numbers are automatically converted before comparison. Note that two NaN values are always treated as unequal.
  • Two JSON null values are equal.
Note
Floating-point inside JSON values numbers are compared with json::number_float_t::operator== which is double::operator== by default. To compare floating-point while respecting an epsilon, an alternative comparison function could be used, for instance
inline bool is_same(T a, T b, T epsilon = std::numeric_limits<T>::epsilon()) noexcept
{
return std::abs(a - b) <= epsilon;
}
int int FloatType value
Definition: json.h:15223
Or you can self-defined operator equal function like this:
bool my_equal(const_reference lhs, const_reference rhs) {
const auto lhs_type lhs.type();
const auto rhs_type rhs.type();
if (lhs_type == rhs_type) {
switch(lhs_type)
// self_defined case
return std::abs(lhs - rhs) <= std::numeric_limits<float>::epsilon();
// other cases remain the same with the original
...
}
...
}
const value_type & const_reference
the type of an element const reference
Definition: json.h:16769
@ number_float
number value (floating-point)
NaN values never compare equal to themselves or to other NaN values.
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are equal

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@complexity Linear.

@liveexample{The example demonstrates comparing several JSON types.,operator__equal}

Since
version 1.0.0

Definition at line 22695 of file json.h.

◆ operator== [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator== ( const_reference  lhs,
const ScalarType  rhs 
)
friend

comparison: equal

comparison: equal Compares two JSON values for equality according to the following rules:

  • Two JSON values are equal if (1) they are from the same type and (2) their stored values are the same according to their respective operator==.
  • Integer and floating-point numbers are automatically converted before comparison. Note that two NaN values are always treated as unequal.
  • Two JSON null values are equal.
Note
Floating-point inside JSON values numbers are compared with json::number_float_t::operator== which is double::operator== by default. To compare floating-point while respecting an epsilon, an alternative comparison function could be used, for instance
inline bool is_same(T a, T b, T epsilon = std::numeric_limits<T>::epsilon()) noexcept
{
return std::abs(a - b) <= epsilon;
}
Or you can self-defined operator equal function like this:
bool my_equal(const_reference lhs, const_reference rhs) {
const auto lhs_type lhs.type();
const auto rhs_type rhs.type();
if (lhs_type == rhs_type) {
switch(lhs_type)
// self_defined case
return std::abs(lhs - rhs) <= std::numeric_limits<float>::epsilon();
// other cases remain the same with the original
...
}
...
}
NaN values never compare equal to themselves or to other NaN values.
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are equal

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@complexity Linear.

@liveexample{The example demonstrates comparing several JSON types.,operator__equal}

Since
version 1.0.0

Definition at line 22684 of file json.h.

◆ operator== [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
bool operator== ( const_reference  lhs,
const_reference  rhs 
)
friend

comparison: equal

Compares two JSON values for equality according to the following rules:

  • Two JSON values are equal if (1) they are from the same type and (2) their stored values are the same according to their respective operator==.
  • Integer and floating-point numbers are automatically converted before comparison. Note that two NaN values are always treated as unequal.
  • Two JSON null values are equal.
Note
Floating-point inside JSON values numbers are compared with json::number_float_t::operator== which is double::operator== by default. To compare floating-point while respecting an epsilon, an alternative comparison function could be used, for instance
inline bool is_same(T a, T b, T epsilon = std::numeric_limits<T>::epsilon()) noexcept
{
return std::abs(a - b) <= epsilon;
}
Or you can self-defined operator equal function like this:
bool my_equal(const_reference lhs, const_reference rhs) {
const auto lhs_type lhs.type();
const auto rhs_type rhs.type();
if (lhs_type == rhs_type) {
switch(lhs_type)
// self_defined case
return std::abs(lhs - rhs) <= std::numeric_limits<float>::epsilon();
// other cases remain the same with the original
...
}
...
}
NaN values never compare equal to themselves or to other NaN values.
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are equal

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@complexity Linear.

@liveexample{The example demonstrates comparing several JSON types.,operator__equal}

Since
version 1.0.0

Definition at line 22610 of file json.h.

◆ operator> [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator> ( const ScalarType  lhs,
const_reference  rhs 
)
friend

comparison: greater than

comparison: greater than Compares whether one JSON value lhs is greater than another JSON value by calculating not (lhs <= rhs).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is greater than to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__lessequal}

Since
version 1.0.0

Definition at line 22953 of file json.h.

◆ operator> [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator> ( const_reference  lhs,
const ScalarType  rhs 
)
friend

comparison: greater than

comparison: greater than Compares whether one JSON value lhs is greater than another JSON value by calculating not (lhs <= rhs).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is greater than to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__lessequal}

Since
version 1.0.0

Definition at line 22942 of file json.h.

◆ operator> [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is greater than to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__lessequal}

Since
version 1.0.0

Definition at line 22931 of file json.h.

◆ operator>= [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator>= ( const ScalarType  lhs,
const_reference  rhs 
)
friend

comparison: greater than or equal

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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is greater than or equal to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__greaterequal}

Since
version 1.0.0

Definition at line 22999 of file json.h.

◆ operator>= [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0>
bool operator>= ( const_reference  lhs,
const ScalarType  rhs 
)
friend

comparison: greater than or equal

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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is greater than or equal to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__greaterequal}

Since
version 1.0.0

Definition at line 22988 of file json.h.

◆ operator>= [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
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).

Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is greater than or equal to rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__greaterequal}

Since
version 1.0.0

Definition at line 22977 of file json.h.

◆ swap

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void swap ( reference  left,
reference  right 
)
friend

exchanges the values

Exchanges the contents of the JSON value from left with those of right. 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. implemented as a friend function callable via ADL.

Parameters
[in,out]leftJSON value to exchange the contents with
[in,out]rightJSON value to exchange the contents with

@complexity Constant.

@liveexample{The example below shows how JSON values can be swapped with swap().,swap__reference}

Since
version 1.0.0

Definition at line 22389 of file json.h.

Member Data Documentation

◆ allow_exceptions

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
JSON_HEDLEY_WARN_UNUSED_RESULT std::size_t const bool const bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::allow_exceptions = true

◆ const

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
const char* default_value nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::const
Initial value:
{
return value(ptr, string_t(default_value))
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.h:20279
StringType string_t
a type for a string
Definition: json.h:17090

Definition at line 20375 of file json.h.

◆ format [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::format = input_format_t::json

Definition at line 23292 of file json.h.

◆ format [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool class SAX IteratorType SAX input_format_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::format = input_format_t::json

Definition at line 23305 of file json.h.

◆ ignore_comments [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::ignore_comments
Initial value:
= false)
{
auto ia = detail::input_adapter(std::forward<InputType>(i));
? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
: detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
}
template<class IteratorType
SAX input_format_t const bool const bool ignore_comments
Definition: json.h:23294
static ::nlohmann::detail::parser< basic_json, InputAdapterType > parser(InputAdapterType adapter, detail::parser_callback_t< basic_json >cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
Definition: json.h:16684
SAX input_format_t const bool strict
Definition: json.h:23293
SAX input_format_t format
Definition: json.h:23292
iterator_input_adapter_factory< IteratorType >::adapter_type input_adapter(IteratorType first, IteratorType last)
Definition: json.h:5088
nlohmann::json json
Definition: umbridge.h:15

Definition at line 23294 of file json.h.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::accept(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_DEPRECATED_FOR(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parse(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::parser().

◆ ignore_comments [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool class SAX IteratorType SAX input_format_t const bool const bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::ignore_comments

Definition at line 23307 of file json.h.

◆ last

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool class SAX IteratorType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::last

◆ len

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
JSON_HEDLEY_WARN_UNUSED_RESULT std::size_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::len

Definition at line 23992 of file json.h.

◆ m_value

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
json_value nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::m_value = {}

the value of the current element

Definition at line 23447 of file json.h.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::assert_invariant(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::at(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::basic_json(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::clear(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::contains(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::count(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::json_value::destroy(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::emplace_back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::empty(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::find(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get_impl_ptr(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::insert_iterator(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::JSON_HEDLEY_NON_NULL(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::max_size(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator=(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[](), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::size(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::swap(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::update(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::~basic_json().

◆ sax [1/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::sax

Definition at line 23291 of file json.h.

◆ sax [2/2]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool class SAX IteratorType SAX* nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::sax

Definition at line 23304 of file json.h.

◆ strict [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::strict = true

◆ strict [2/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
SAX input_format_t const bool const bool class SAX IteratorType SAX input_format_t const bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::strict = true

Definition at line 23306 of file json.h.

◆ strict [3/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
JSON_HEDLEY_WARN_UNUSED_RESULT std::size_t const bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::strict = true

Definition at line 23993 of file json.h.


The documentation for this class was generated from the following file: