Flow123d  JS_before_hm-1008-g3dab983
Classes | Public Types | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > Class Template Reference

a class to store JSON values More...

#include <json.hpp>

Collaboration diagram for nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >:
Collaboration graph
[legend]

Classes

class  const_iterator
 a const random access iterator for the basic_json class More...
 
struct  internal_iterator
 an iterator value More...
 
class  iteration_proxy
 proxy class for the iterator_wrapper functions More...
 
class  iterator
 a mutable random access iterator for the basic_json class More...
 
class  json_reverse_iterator
 a template for a reverse iterator class More...
 
union  json_value
 a JSON value More...
 
class  lexer
 lexical analysis More...
 
class  parser
 syntax analysis More...
 
class  primitive_iterator_t
 an iterator for primitive JSON types More...
 

Public Types

enum  value_t : uint8_t {
  value_t::null, value_t::object, value_t::array, value_t::string,
  value_t::boolean, value_t::number_integer, value_t::number_unsigned, value_t::number_float,
  value_t::discarded
}
 the JSON type enumeration More...
 
enum  parse_event_t : uint8_t {
  parse_event_t::object_start, parse_event_t::object_end, parse_event_t::array_start, parse_event_t::array_end,
  parse_event_t::key, parse_event_t::value
}
 JSON callback events. More...
 
using parser_callback_t = std::function< bool(int depth, parse_event_t event, basic_json &parsed)>
 per-element parser callback type More...
 

Static Public Member Functions

static allocator_type get_allocator ()
 returns the allocator associated with the container More...
 

Private Types

using basic_json_t = basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >
 workaround type for MSVC More...
 

Private Member Functions

template<class T , typename std::enable_if< std::is_convertible< typename object_t::key_type, typename T::key_type >::value andstd::is_convertible< basic_json_t, typename T::mapped_type >::value, int >::type = 0>
get_impl (T *) const
 get an object (explicit) More...
 
object_t get_impl (object_t *) const
 get an object (explicit) More...
 
template<class T , typename std::enable_if< std::is_convertible< basic_json_t, typename T::value_type >::value andnot std::is_same< basic_json_t, typename T::value_type >::value andnot std::is_arithmetic< T >::value andnot std::is_convertible< std::string, T >::value andnot has_mapped_type< T >::value, int >::type = 0>
get_impl (T *) const
 get an array (explicit) More...
 
template<class T , typename std::enable_if< std::is_convertible< basic_json_t, T >::value andnot std::is_same< basic_json_t, T >::value, int >::type = 0>
std::vector< T > get_impl (std::vector< T > *) const
 get an array (explicit) More...
 
template<class T , typename std::enable_if< std::is_same< basic_json, typename T::value_type >::value andnot has_mapped_type< T >::value, int >::type = 0>
get_impl (T *) const
 get an array (explicit) More...
 
array_t get_impl (array_t *) const
 get an array (explicit) More...
 
template<typename T , typename std::enable_if< std::is_convertible< string_t, T >::value, int >::type = 0>
get_impl (T *) const
 get a string (explicit) More...
 
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value, int >::type = 0>
get_impl (T *) const
 get a number (explicit) More...
 
constexpr boolean_t get_impl (boolean_t *) const
 get a boolean (explicit) More...
 
object_tget_impl_ptr (object_t *) noexcept
 get a pointer to the value (object) More...
 
constexpr const object_tget_impl_ptr (const object_t *) const noexcept
 get a pointer to the value (object) More...
 
array_tget_impl_ptr (array_t *) noexcept
 get a pointer to the value (array) More...
 
constexpr const array_tget_impl_ptr (const array_t *) const noexcept
 get a pointer to the value (array) More...
 
string_tget_impl_ptr (string_t *) noexcept
 get a pointer to the value (string) More...
 
constexpr const string_tget_impl_ptr (const string_t *) const noexcept
 get a pointer to the value (string) More...
 
boolean_tget_impl_ptr (boolean_t *) noexcept
 get a pointer to the value (boolean) More...
 
constexpr const boolean_tget_impl_ptr (const boolean_t *) const noexcept
 get a pointer to the value (boolean) More...
 
number_integer_tget_impl_ptr (number_integer_t *) noexcept
 get a pointer to the value (integer number) More...
 
constexpr const number_integer_tget_impl_ptr (const number_integer_t *) const noexcept
 get a pointer to the value (integer number) More...
 
number_unsigned_tget_impl_ptr (number_unsigned_t *) noexcept
 get a pointer to the value (unsigned number) More...
 
constexpr const number_unsigned_tget_impl_ptr (const number_unsigned_t *) const noexcept
 get a pointer to the value (unsigned number) More...
 
number_float_tget_impl_ptr (number_float_t *) noexcept
 get a pointer to the value (floating-point number) More...
 
constexpr const number_float_tget_impl_ptr (const number_float_t *) const noexcept
 get a pointer to the value (floating-point number) More...
 
string_t type_name () const noexcept
 return the type as string More...
 
void dump (std::ostream &o, const bool pretty_print, const unsigned int indent_step, const unsigned int current_indent=0) const
 internal implementation of the serialization function More...
 

Static Private Member Functions

template<typename T , typename... Args>
static T * create (Args &&...args)
 helper for exception-safe object creation More...
 
template<typename ReferenceType , typename ThisType >
static ReferenceType get_ref_impl (ThisType &obj)
 helper function to implement get_ref() More...
 
static std::size_t extra_space (const string_t &s) noexcept
 calculates the extra space to escape a JSON string More...
 
static string_t escape_string (const string_t &s)
 escape a string More...
 

Private Attributes

value_t m_type = value_t::null
 the type of the current element More...
 
json_value m_value = {}
 the value of the current element More...
 

container types

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

using object_t = ObjectType< StringType, basic_json, std::less< StringType >, 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...
 

constructors and destructors

static basic_json array (std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
 explicitly create an array from an initializer list More...
 
static basic_json object (std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
 explicitly create an object from an initializer list More...
 
 basic_json (const value_t value_type)
 create an empty value with a given type More...
 
 basic_json ()=default
 create a null object (implicitly) More...
 
 basic_json (std::nullptr_t) noexcept
 create a null object (explicitly) More...
 
 basic_json (const object_t &val)
 create an object (explicit) More...
 
template<class CompatibleObjectType , typename std::enable_if< std::is_constructible< typename object_t::key_type, typename CompatibleObjectType::key_type >::value andstd::is_constructible< basic_json, typename CompatibleObjectType::mapped_type >::value, int >::type = 0>
 basic_json (const CompatibleObjectType &val)
 create an object (implicit) More...
 
 basic_json (const array_t &val)
 create an array (explicit) More...
 
template<class CompatibleArrayType , typename std::enable_if< not std::is_same< CompatibleArrayType, typename basic_json_t::iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::const_iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::reverse_iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::const_reverse_iterator >::value andnot std::is_same< CompatibleArrayType, typename array_t::iterator >::value andnot std::is_same< CompatibleArrayType, typename array_t::const_iterator >::value andstd::is_constructible< basic_json, typename CompatibleArrayType::value_type >::value, int >::type = 0>
 basic_json (const CompatibleArrayType &val)
 create an array (implicit) More...
 
 basic_json (const string_t &val)
 create a string (explicit) More...
 
 basic_json (const typename string_t::value_type *val)
 create a string (explicit) More...
 
template<class CompatibleStringType , typename std::enable_if< std::is_constructible< string_t, CompatibleStringType >::value, int >::type = 0>
 basic_json (const CompatibleStringType &val)
 create a string (implicit) More...
 
 basic_json (boolean_t val) noexcept
 create a boolean (explicit) More...
 
template<typename T , typename std::enable_if< not(std::is_same< T, int >::value) and std::is_same< T, number_integer_t >::value, int >::type = 0>
 basic_json (const number_integer_t val) noexcept
 create an integer number (explicit) More...
 
 basic_json (const int val) noexcept
 create an integer number from an enum type (explicit) More...
 
template<typename CompatibleNumberIntegerType , typename std::enable_if< std::is_constructible< number_integer_t, CompatibleNumberIntegerType >::value andstd::numeric_limits< CompatibleNumberIntegerType >::is_integer andstd::numeric_limits< CompatibleNumberIntegerType >::is_signed, CompatibleNumberIntegerType >::type = 0>
 basic_json (const CompatibleNumberIntegerType val) noexcept
 create an integer number (implicit) More...
 
template<typename T , typename std::enable_if< not(std::is_same< T, int >::value) and std::is_same< T, number_unsigned_t >::value, int >::type = 0>
 basic_json (const number_unsigned_t val) noexcept
 create an unsigned integer number (explicit) More...
 
template<typename CompatibleNumberUnsignedType , typename std::enable_if< std::is_constructible< number_unsigned_t, CompatibleNumberUnsignedType >::value andstd::numeric_limits< CompatibleNumberUnsignedType >::is_integer and!std::numeric_limits< CompatibleNumberUnsignedType >::is_signed, CompatibleNumberUnsignedType >::type = 0>
 basic_json (const CompatibleNumberUnsignedType val) noexcept
 create an unsigned number (implicit) More...
 
 basic_json (const number_float_t val) noexcept
 create a floating-point number (explicit) More...
 
template<typename CompatibleNumberFloatType , typename = typename std::enable_if< std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and std::is_floating_point<CompatibleNumberFloatType>::value>::type>
 basic_json (const CompatibleNumberFloatType val) noexcept
 create an floating-point number (implicit) More...
 
 basic_json (std::initializer_list< basic_json > init, bool type_deduction=true, value_t manual_type=value_t::array)
 create a container (array or object) from an initializer list 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 orstd::is_same< InputIT, typename basic_json_t::const_iterator >::value, int >::type = 0>
 basic_json (InputIT first, InputIT last)
 construct a JSON container given an iterator range More...
 
 basic_json (std::istream &i, parser_callback_t cb=nullptr)
 construct a JSON value given an input stream More...
 
 basic_json (const basic_json &other)
 copy constructor More...
 
 basic_json (basic_json &&other) noexcept
 move constructor More...
 
referenceoperator= (basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value andstd::is_nothrow_move_assignable< value_t >::value andstd::is_nothrow_move_constructible< json_value >::value andstd::is_nothrow_move_assignable< json_value >::value)
 copy assignment More...
 
 ~basic_json ()
 destructor More...
 

object inspection

string_t dump (const int indent=-1) 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_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

template<typename ValueType , typename std::enable_if< not std::is_pointer< ValueType >::value, int >::type = 0>
ValueType get () const
 get a value (explicit) More...
 
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
PointerType get () noexcept
 get a pointer value (explicit) More...
 
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
constexpr const PointerType get () const noexcept
 get a pointer value (explicit) More...
 
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
PointerType get_ptr () noexcept
 get a pointer value (implicit) More...
 
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::valueand std::is_const< typename std::remove_pointer< PointerType >::type >::value, int >::type = 0>
constexpr const PointerType get_ptr () const noexcept
 get a pointer value (implicit) 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 >::valueand 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< not std::is_pointer< ValueType >::valueand not std::is_same< ValueType, typename string_t::value_type >::valueand not std::is_same< ValueType, std::initializer_list< typename string_t::value_type >>::value, int >::type = 0>
 operator ValueType () const
 get a value (implicit) More...
 

element access

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 , std::size_t n>
reference operator[] (T *(&key)[n])
 access specified object element More...
 
template<typename T , std::size_t n>
const_reference operator[] (T *(&key)[n]) const
 read-only access specified object element More...
 
template<typename T >
reference operator[] (T *key)
 access specified object element More...
 
template<typename T >
const_reference operator[] (T *key) const
 read-only access specified object element More...
 
template<class ValueType , typename std::enable_if< std::is_convertible< basic_json_t, ValueType >::value, int >::type = 0>
ValueType value (const typename object_t::key_type &key, ValueType default_value) const
 access specified object element with default value 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...
 
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 InteratorType , typename std::enable_if< std::is_same< InteratorType, typename basic_json_t::iterator >::value orstd::is_same< InteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0>
InteratorType erase (InteratorType pos)
 remove element given an iterator More...
 
template<class InteratorType , typename std::enable_if< std::is_same< InteratorType, typename basic_json_t::iterator >::value orstd::is_same< InteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0>
InteratorType erase (InteratorType first, InteratorType last)
 remove elements given an iterator range More...
 
size_type erase (const typename object_t::key_type &key)
 remove element from a JSON object given a key More...
 
void erase (const size_type idx)
 remove element from a JSON array given an index More...
 

lookup

iterator find (typename object_t::key_type key)
 find an element in a JSON object More...
 
const_iterator find (typename object_t::key_type key) const
 find an element in a JSON object More...
 
size_type count (typename object_t::key_type key) const
 returns the number of occurrences of a key in a JSON object More...
 

iterators

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

capacity

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

modifiers

void 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...
 
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, std::initializer_list< basic_json > ilist)
 inserts elements More...
 
void swap (reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value andstd::is_nothrow_move_assignable< value_t >::value andstd::is_nothrow_move_constructible< json_value >::value andstd::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...
 

lexicographical comparison operators

bool operator< (const value_t lhs, const value_t rhs) noexcept
 comparison operator for JSON types More...
 
bool operator== (const_reference lhs, const_reference rhs) noexcept
 comparison: equal More...
 
bool operator== (const_reference v, std::nullptr_t) noexcept
 comparison: equal More...
 
bool operator== (std::nullptr_t, const_reference v) noexcept
 comparison: equal More...
 
bool operator!= (const_reference lhs, const_reference rhs) noexcept
 comparison: not equal More...
 
bool operator!= (const_reference v, std::nullptr_t) noexcept
 comparison: not equal More...
 
bool operator!= (std::nullptr_t, const_reference v) noexcept
 comparison: not equal More...
 
bool operator< (const_reference lhs, const_reference rhs) noexcept
 comparison: less than More...
 
bool operator<= (const_reference lhs, const_reference rhs) noexcept
 comparison: less than or equal More...
 
bool operator> (const_reference lhs, const_reference rhs) noexcept
 comparison: greater than More...
 
bool operator>= (const_reference lhs, const_reference rhs) noexcept
 comparison: greater than or equal More...
 

serialization

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

deserialization

static basic_json parse (const string_t &s, parser_callback_t cb=nullptr)
 deserialize from string More...
 
static basic_json parse (std::istream &i, parser_callback_t cb=nullptr)
 deserialize from stream More...
 
static basic_json parse (std::istream &&i, parser_callback_t cb=nullptr)
 deserialize from stream More...
 
std::istream & operator<< (basic_json &j, std::istream &i)
 deserialize from stream More...
 
std::istream & operator>> (std::istream &i, basic_json &j)
 deserialize from stream More...
 

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>
class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >

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)
AllocatorTypetype of the allocator to use (std::allocator by default)

The class satisfies the following concept requirements:

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

Definition at line 173 of file json.hpp.

Member Typedef Documentation

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

the allocator type

Definition at line 209 of file json.hpp.

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

basic_json, // value_type
std::allocator<basic_json> // allocator_type
>

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 constraint explicitly. 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 379 of file json.hpp.

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

workaround type for MSVC

Definition at line 184 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::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 452 of file json.hpp.

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

the type of an element const pointer

Definition at line 214 of file json.hpp.

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

the type of an element const reference

Definition at line 201 of file json.hpp.

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

a const reverse iterator for a basic_json container

Definition at line 226 of file json.hpp.

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

a type to represent differences between iterators

Definition at line 204 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::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 663 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::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 523 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::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 595 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::object_t = ObjectType<StringType, basic_json, std::less<StringType>, 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::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, later stored name/value pairs overwrite previously stored name/value pairs, leaving the used names unique. For instance, {"key": 1} and {"key": 2, "key": 1} will be treated as equal and both stored as {"key": 1}.
  • 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 constraint explicitly. 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 333 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>

per-element parser callback type

With a parser callback function, the result of parsing a JSON text can be influenced. When passed to parse(std::istream&, parser_callback_t) or parse(const string_t&, parser_callback_t), 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

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(std::istream&, parser_callback_t) or parse(const string_t&, parser_callback_t) for examples
Since
version 1.0.0

Definition at line 901 of file json.hpp.

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

the type of an element pointer

Definition at line 212 of file json.hpp.

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

the type of an element reference

Definition at line 199 of file json.hpp.

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

a reverse iterator for a basic_json container

Definition at line 224 of file json.hpp.

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

a type to represent container sizes

Definition at line 206 of file json.hpp.

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

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 426 of file json.hpp.

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

the type of elements in a basic_json container

Definition at line 196 of file json.hpp.

Member Enumeration Documentation

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
enum nlohmann::basic_json::parse_event_t : uint8_t
strong

JSON callback events.

This enumeration lists the parser events that can trigger calling a callback function of type parser_callback_t during parsing.

Since
version 1.0.0
Enumerator
object_start 

the parser read { and started to process a JSON 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

key 

the parser read a key of a value in an object

value 

the parser finished reading a JSON value

Definition at line 836 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
enum nlohmann::basic_json::value_t : uint8_t
strong

the JSON type enumeration

This enumeration collects the different JSON types. It is internally used to distinguish the stored values, and the functions is_null(), is_object(), is_array(), is_string(), is_boolean(), is_number(), and is_discarded() rely on it.

Since
version 1.0.0
Enumerator
null 

null value

object 

object (unordered set of name/value pairs)

array 

array (ordered collection of values)

string 

string value

boolean 

boolean value

number_integer 

number value (integer)

number_unsigned 

number value (unsigned integer)

number_float 

number value (floating-point)

discarded 

discarded by the the parser callback function

Definition at line 682 of file json.hpp.

Constructor & Destructor Documentation

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const value_t  value_type)
inline

create an empty value with a given type

Create an empty JSON value with a given type. The value will be default initialized with an empty value which depends on the type:

Value type initial value
null null
boolean false
string ""
number 0
object {}
array []
Parameters
[in]value_typethe type of the value to create

Constant.

Exceptions
std::bad_allocif allocation for object, array, or string value fails

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

See also
basic_json(std::nullptr_t)create a null value
basic_json(boolean_t value)create a boolean value
basic_json(const string_t&)create a string value
basic_json(const object_t&)create a object value
basic_json(const array_t&)create a array value
basic_json(const number_float_t)create a number (floating-point) value
basic_json(const number_integer_t)create a number (integer) value
basic_json(const number_unsigned_t)create a number (unsigned) value
Since
version 1.0.0

Definition at line 950 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( )
default

create a null object (implicitly)

Create a null JSON value. This is the implicit version of the null value constructor as it takes no parameters.

Constant.

No-throw guarantee: this constructor never throws exceptions.

This function helps basic_json satisfying the Container requirements:

{The following code shows the constructor for a null JSON value.,basic_json}

See also
basic_json(std::nullptr_t)create a null value
Since
version 1.0.0
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( std::nullptr_t  )
inlinenoexcept

create a null object (explicitly)

Create a null JSON value. This is the explicitly version of the null value constructor as it takes a null pointer as parameter. It allows to create null values by explicitly assigning a nullptr to a JSON value. The passed null pointer itself is not read – it is only used to choose the right constructor.

Constant.

No-throw guarantee: this constructor never throws exceptions.

{The following code shows the constructor with null pointer parameter.,basic_json__nullptr_t}

See also
basic_json() – default constructor (implicitly creating a null value)
Since
version 1.0.0

Definition at line 1002 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const object_t val)
inline

create an object (explicit)

Create an object JSON value with a given content.

Parameters
[in]vala value for the object

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for object value fails

{The following code shows the constructor with an object_t parameter.,basic_json__object_t}

See also
basic_json(const CompatibleObjectType&)create an object value from a compatible STL container
Since
version 1.0.0

Definition at line 1025 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class CompatibleObjectType , typename std::enable_if< std::is_constructible< typename object_t::key_type, typename CompatibleObjectType::key_type >::value andstd::is_constructible< basic_json, typename CompatibleObjectType::mapped_type >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const CompatibleObjectType &  val)
inline

create an object (implicit)

Create an object JSON value with a given content. This constructor allows any type CompatibleObjectType that can be used to construct values of type object_t.

Template Parameters
CompatibleObjectTypeAn object type whose key_type and value_type is compatible to object_t. Examples include std::map, std::unordered_map, std::multimap, and std::unordered_multimap with a key_type of std::string, and a value_type from which a basic_json value can be constructed.
Parameters
[in]vala value for the object

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for object value fails

{The following code shows the constructor with several compatible object type parameters.,basic_json__CompatibleObjectType}

See also
basic_json(const object_t&)create an object value
Since
version 1.0.0

Definition at line 1060 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const array_t val)
inline

create an array (explicit)

Create an array JSON value with a given content.

Parameters
[in]vala value for the array

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for array value fails

{The following code shows the constructor with an array_t parameter.,basic_json__array_t}

See also
basic_json(const CompatibleArrayType&)create an array value from a compatible STL containers
Since
version 1.0.0

Definition at line 1087 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class CompatibleArrayType , typename std::enable_if< not std::is_same< CompatibleArrayType, typename basic_json_t::iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::const_iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::reverse_iterator >::value andnot std::is_same< CompatibleArrayType, typename basic_json_t::const_reverse_iterator >::value andnot std::is_same< CompatibleArrayType, typename array_t::iterator >::value andnot std::is_same< CompatibleArrayType, typename array_t::const_iterator >::value andstd::is_constructible< basic_json, typename CompatibleArrayType::value_type >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const CompatibleArrayType &  val)
inline

create an array (implicit)

Create an array JSON value with a given content. This constructor allows any type CompatibleArrayType that can be used to construct values of type array_t.

Template Parameters
CompatibleArrayTypeAn object type whose value_type is compatible to array_t. Examples include std::vector, std::deque, std::list, std::forward_list, std::array, std::set, std::unordered_set, std::multiset, and unordered_multiset with a value_type from which a basic_json value can be constructed.
Parameters
[in]vala value for the array

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for array value fails

{The following code shows the constructor with several compatible array type parameters.,basic_json__CompatibleArrayType}

See also
basic_json(const array_t&)create an array value
Since
version 1.0.0

Definition at line 1127 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const string_t val)
inline

create a string (explicit)

Create an string JSON value with a given content.

Parameters
[in]vala value for the string

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for string value fails

{The following code shows the constructor with an string_t parameter.,basic_json__string_t}

See also
basic_json(const typename string_t::value_type*)create a string value from a character pointer
basic_json(const CompatibleStringType&)create a string value from a compatible string container
Since
version 1.0.0

Definition at line 1156 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const typename string_t::value_type *  val)
inline

create a string (explicit)

Create a string JSON value with a given content.

Parameters
[in]vala literal value for the string

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for string value fails

{The following code shows the constructor with string literal parameter.,basic_json__string_t_value_type}

See also
basic_json(const string_t&)create a string value
basic_json(const CompatibleStringType&)create a string value from a compatible string container
Since
version 1.0.0

Definition at line 1180 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class CompatibleStringType , typename std::enable_if< std::is_constructible< string_t, CompatibleStringType >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const CompatibleStringType &  val)
inline

create a string (implicit)

Create a string JSON value with a given content.

Parameters
[in]vala value for the string
Template Parameters
CompatibleStringTypean string type which is compatible to string_t, for instance std::string.

Linear in the size of the passed val.

Exceptions
std::bad_allocif allocation for string value fails

{The following code shows the construction of a string value from a compatible type.,basic_json__CompatibleStringType}

See also
basic_json(const string_t&)create a string value
basic_json(const typename string_t::value_type*)create a string value from a character pointer
Since
version 1.0.0

Definition at line 1211 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( boolean_t  val)
inlinenoexcept

create a boolean (explicit)

Creates a JSON boolean type from a given value.

Parameters
[in]vala boolean value to store

Constant.

{The example below demonstrates boolean values.,basic_json__boolean_t}

Since
version 1.0.0

Definition at line 1229 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T , typename std::enable_if< not(std::is_same< T, int >::value) and std::is_same< T, number_integer_t >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const number_integer_t  val)
inlinenoexcept

create an integer number (explicit)

Create an integer number JSON value with a given content.

Template Parameters
TA helper type to remove this function via SFINAE in case number_integer_t is the same as int. In this case, this constructor would have the same signature as basic_json(const int value). Note the helper type T is not visible in this constructor's interface.
Parameters
[in]valan integer to create a JSON number from

Constant.

{The example below shows the construction of an integer number value.,basic_json__number_integer_t}

See also
basic_json(const int)create a number value (integer)
basic_json(const CompatibleNumberIntegerType)create a number value (integer) from a compatible number type
Since
version 1.0.0

Definition at line 1262 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const int  val)
inlinenoexcept

create an integer number from an enum type (explicit)

Create an integer number JSON value with a given content.

Parameters
[in]valan integer to create a JSON number from
Note
This constructor allows to pass enums directly to a constructor. As C++ has no way of specifying the type of an anonymous enum explicitly, we can only rely on the fact that such values implicitly convert to int. As int may already be the same type of number_integer_t, we may need to switch off the constructor basic_json(const number_integer_t).

Constant.

{The example below shows the construction of an integer number value from an anonymous enum.,basic_json__const_int}

See also
basic_json(const number_integer_t)create a number value (integer)
basic_json(const CompatibleNumberIntegerType)create a number value (integer) from a compatible number type
Since
version 1.0.0

Definition at line 1291 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename CompatibleNumberIntegerType , typename std::enable_if< std::is_constructible< number_integer_t, CompatibleNumberIntegerType >::value andstd::numeric_limits< CompatibleNumberIntegerType >::is_integer andstd::numeric_limits< CompatibleNumberIntegerType >::is_signed, CompatibleNumberIntegerType >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const CompatibleNumberIntegerType  val)
inlinenoexcept

create an integer number (implicit)

Create an integer number JSON value with a given content. This constructor allows any type CompatibleNumberIntegerType that can be used to construct values of type number_integer_t.

Template Parameters
CompatibleNumberIntegerTypeAn integer type which is compatible to number_integer_t. Examples include the types int, int32_t, long, and short.
Parameters
[in]valan integer to create a JSON number from

Constant.

{The example below shows the construction of several integer number values from compatible types.,basic_json__CompatibleIntegerNumberType}

See also
basic_json(const number_integer_t)create a number value (integer)
basic_json(const int)create a number value (integer)
Since
version 1.0.0

Definition at line 1328 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T , typename std::enable_if< not(std::is_same< T, int >::value) and std::is_same< T, number_unsigned_t >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const number_unsigned_t  val)
inlinenoexcept

create an unsigned integer number (explicit)

Create an unsigned integer number JSON value with a given content.

Template Parameters
Thelper type to compare number_unsigned_t and unsigned int (not visible in) the interface.
Parameters
[in]valan integer to create a JSON number from

Constant.

See also
basic_json(const CompatibleNumberUnsignedType)create a number value (unsigned integer) from a compatible number type
Since
version 2.0.0

Definition at line 1356 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename CompatibleNumberUnsignedType , typename std::enable_if< std::is_constructible< number_unsigned_t, CompatibleNumberUnsignedType >::value andstd::numeric_limits< CompatibleNumberUnsignedType >::is_integer and!std::numeric_limits< CompatibleNumberUnsignedType >::is_signed, CompatibleNumberUnsignedType >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const CompatibleNumberUnsignedType  val)
inlinenoexcept

create an unsigned number (implicit)

Create an unsigned number JSON value with a given content. This constructor allows any type CompatibleNumberUnsignedType that can be used to construct values of type number_unsigned_t.

Template Parameters
CompatibleNumberUnsignedTypeAn integer type which is compatible to number_unsigned_t. Examples may include the types unsigned int, uint32_t, or unsigned short.
Parameters
[in]valan unsigned integer to create a JSON number from

Constant.

See also
basic_json(const number_unsigned_t)create a number value (unsigned)
Since
version 2.0.0

Definition at line 1387 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const number_float_t  val)
inlinenoexcept

create a floating-point number (explicit)

Create a floating-point number JSON value with a given content.

Parameters
[in]vala floating-point value to create a JSON number from
Note
RFC 7159, section 6 disallows NaN values:

Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

In case the parameter val is not a number, a JSON null value is created instead.

Constant.

{The following example creates several floating-point values.,basic_json__number_float_t}

See also
basic_json(const CompatibleNumberFloatType)create a number value (floating-point) from a compatible number type
Since
version 1.0.0

Definition at line 1416 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename CompatibleNumberFloatType , typename = typename std::enable_if< std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and std::is_floating_point<CompatibleNumberFloatType>::value>::type>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( const CompatibleNumberFloatType  val)
inlinenoexcept

create an floating-point number (implicit)

Create an floating-point number JSON value with a given content. This constructor allows any type CompatibleNumberFloatType that can be used to construct values of type number_float_t.

Template Parameters
CompatibleNumberFloatTypeA floating-point type which is compatible to number_float_t. Examples may include the types float or double.
Parameters
[in]vala floating-point to create a JSON number from
Note
RFC 7159, section 6 disallows NaN values:

Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.

In case the parameter val is not a number, a JSON null value is created instead.

Constant.

{The example below shows the construction of several floating-point number values from compatible types.,basic_json__CompatibleNumberFloatType}

See also
basic_json(const number_float_t)create a number value (floating-point)
Since
version 1.0.0

Definition at line 1462 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > >  init,
bool  type_deduction = true,
value_t  manual_type = value_t::array 
)
inline

create a container (array or object) from an initializer list

Creates a JSON value of type array or object from the passed initializer list init. In case type_deduction is true (default), the type of the JSON value to be created is deducted from the initializer list init according to the following rules:

  1. If the list is empty, an empty JSON object value {} is created.
  2. If the list consists of pairs whose first element is a string, a JSON object value is created where the first elements of the pairs are treated as keys and the second elements are as values.
  3. In all other cases, an array is created.

The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:

  1. The empty initializer list is written as {} which is exactly an empty JSON object.
  2. C++ has now way of describing mapped types other than to list a list of pairs. As JSON requires that keys must be of type string, rule 2 is the weakest constraint one can pose on initializer lists to interpret them as an object.
  3. In all other cases, the initializer list could not be interpreted as JSON object type, so interpreting it as JSON array type is safe.

With the rules described above, the following JSON values cannot be expressed by an initializer list:

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(std::initializer_list<basic_json>) and object(std::initializer_list<basic_json>).
[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
std::domain_errorif type_deduction is false, manual_type is value_t::object, but init contains an element which is not a pair whose first element is a string; example: "cannot create object from initializer list"

Linear in the size of the initializer list init.

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

See also
array(std::initializer_list<basic_json>)create a JSON array value from an initializer list
object(std::initializer_list<basic_json>)create a JSON object value from an initializer list
Since
version 1.0.0

Definition at line 1535 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( size_type  cnt,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &  val 
)
inline

construct an array with count copies of given value

Constructs a JSON array value by creating cnt copies of a passed value. In case cnt is 0, an empty array is created. As postcondition, std::distance(begin(),end()) == cnt holds.

Parameters
[in]cntthe number of JSON copies of val to create
[in]valthe JSON value to copy

Linear in cnt.

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

Since
version 1.0.0

Definition at line 1691 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class InputIT , typename std::enable_if< std::is_same< InputIT, typename basic_json_t::iterator >::value orstd::is_same< InputIT, typename basic_json_t::const_iterator >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( InputIT  first,
InputIT  last 
)
inline

construct a JSON container given an iterator range

Constructs the JSON value with the contents of the range [first, last). The semantics depends on the different types a JSON value can have:

  • In case of primitive types (number, boolean, or string), first must be begin() and last must be end(). In this case, the value is copied. Otherwise, std::out_of_range is thrown.
  • In case of structured types (array, object), the constructor behaves as similar versions for std::vector.
  • In case of a null type, std::domain_error is thrown.
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)
Exceptions
std::domain_errorif iterators are not compatible; that is, do not belong to the same JSON value; example: "iterators are not compatible"
std::out_of_rangeif iterators are for a primitive type (number, boolean, or string) where an out of range error can be detected easily; example: "iterators out of range"
std::bad_allocif allocation for object, array, or string fails
std::domain_errorif called with a null value; example: "cannot use construct with iterators from null"

Linear in distance between first and last.

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

Since
version 1.0.0

Definition at line 1737 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( std::istream &  i,
parser_callback_t  cb = nullptr 
)
inlineexplicit

construct a JSON value given an input stream

Parameters
[in,out]istream to read a serialized JSON value from
[in]cba parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)

Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.

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

{The example below demonstrates constructing a JSON value from a std::stringstream with and without callback function.,basic_json__istream}

Since
version 2.0.0

Definition at line 1844 of file json.hpp.

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

copy constructor

Creates a copy of a given JSON value.

Parameters
[in]otherthe JSON value to copy

Linear in the size of other.

This function helps basic_json satisfying the Container requirements:

  • The complexity is linear.
  • As postcondition, it holds: other == basic_json(other).
Exceptions
std::bad_allocif allocation for object, array, or string fails.

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

Since
version 1.0.0

Definition at line 1875 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::basic_json ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &&  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
other is a JSON null value

Constant.

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

Since
version 1.0.0

Definition at line 1950 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::~basic_json ( )
inline

destructor

Destroys the JSON value and frees all allocated memory.

Linear.

This function helps basic_json satisfying the Container requirements:

  • The complexity is linear.
  • All stored elements are destroyed and all memory is freed.
Since
version 1.0.0

Definition at line 2010 of file json.hpp.

Member Function Documentation

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::array ( std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > >  init = std::initializer_list<basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >>())
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(std::initializer_list<basic_json>, 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

Linear in the size of init.

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

See also
basic_json(std::initializer_list<basic_json>, bool, value_t)create a JSON value from an initializer list
object(std::initializer_list<basic_json>)create a JSON object value from an initializer list
Since
version 1.0.0

Definition at line 1627 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at ( size_type  idx)
inline

access specified array element with bounds checking

Returns a reference to the element at specified location idx, with bounds checking.

Parameters
[in]idxindex of the element to access
Returns
reference to the element at index idx
Exceptions
std::domain_errorif the JSON value is not an array; example: "cannot use at() with string"
std::out_of_rangeif the index idx is out of range of the array; that is, idx >= size(); example: "array index 7 is out of range"

Constant.

{The example below shows how array elements can be read and written using at().,at__size_type}

Since
version 1.0.0

Definition at line 3019 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at ( size_type  idx) const
inline

access specified array element with bounds checking

Returns a const reference to the element at specified location idx, with bounds checking.

Parameters
[in]idxindex of the element to access
Returns
const reference to the element at index idx
Exceptions
std::domain_errorif the JSON value is not an array; example: "cannot use at() with string"
std::out_of_rangeif the index idx is out of range of the array; that is, idx >= size(); example: "array index 7 is out of range"

Constant.

{The example below shows how array elements can be read using at().,at__size_type_const}

Since
version 1.0.0

Definition at line 3063 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at ( const typename object_t::key_type &  key)
inline

access specified object element with bounds checking

Returns a reference to the element at with specified key key, with bounds checking.

Parameters
[in]keykey of the element to access
Returns
reference to the element at key key
Exceptions
std::domain_errorif the JSON value is not an object; example: "cannot use at() with boolean"
std::out_of_rangeif the key key is is not stored in the object; that is, find(key) == end(); example: "key "the fast" not found"

Logarithmic in the size of the container.

{The example below shows how object elements can be read and written using at().,at__object_t_key_type}

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

Definition at line 3111 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::at ( const typename object_t::key_type &  key) const
inline

access specified object element with bounds checking

Returns a const reference to the element at with specified key key, with bounds checking.

Parameters
[in]keykey of the element to access
Returns
const reference to the element at key key
Exceptions
std::domain_errorif the JSON value is not an object; example: "cannot use at() with boolean"
std::out_of_rangeif the key key is is not stored in the object; that is, find(key) == end(); example: "key "the fast" not found"

Logarithmic in the size of the container.

{The example below shows how object elements can be read using at().,at__object_t_key_type_const}

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

Definition at line 3159 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::back ( )
inline

access the last element

Returns a reference to the last element in the container. For a JSON container c, the expression c.back() is equivalent to

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 cast of number, string, or boolean values, a reference to the value is returned.

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
std::out_of_rangewhen called on null value.

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

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

Definition at line 3665 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::back ( ) const
inline

access the last element

Returns a reference to the last element in the container. For a JSON container c, the expression c.back() is equivalent to

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 cast of number, string, or boolean values, a reference to the value is returned.

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
std::out_of_rangewhen called on null value.

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

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

Definition at line 3675 of file json.hpp.

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

returns an iterator to the first element

Returns an iterator to the first element.

range-begin-end.svg
Illustration from cppreference.com
Returns
iterator to the first element

Constant.

This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.

{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 4101 of file json.hpp.

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

returns a const iterator to the first element

Returns a const iterator to the first element.

range-begin-end.svg
Illustration from cppreference.com
Returns
const iterator to the first element

Constant.

This function helps basic_json satisfying the Container requirements:

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

{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 4111 of file json.hpp.

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

returns a const iterator to the first element

Returns a const iterator to the first element.

range-begin-end.svg
Illustration from cppreference.com
Returns
const iterator to the first element

Constant.

This function helps basic_json satisfying the Container requirements:

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

{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 4141 of file json.hpp.

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

returns a const iterator to one past the last element

Returns a const iterator to one past the last element.

range-begin-end.svg
Illustration from cppreference.com
Returns
const iterator one past the last element

Constant.

This function helps basic_json satisfying the Container requirements:

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

{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 4212 of file json.hpp.

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

Value type initial value
null null
boolean false
string ""
number 0
object {}
array []
Note
Floating-point numbers are set to 0.0 which will be serialized to 0. The vale type remains number_float_t.

Linear in the size of the JSON value.

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

Since
version 1.0.0

Definition at line 4610 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::count ( typename object_t::key_type  key) const
inline

returns the number of occurrences of a key in a JSON object

Returns the number of elements with key key. If ObjectType is the default std::map type, the return value will always be 0 (key was not found) or 1 (key was found).

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.

Logarithmic in the size of the JSON object.

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

Since
version 1.0.0

Definition at line 4060 of file json.hpp.

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

range-rbegin-rend.svg
Illustration from cppreference.com

Constant.

This function helps basic_json satisfying the ReversibleContainer requirements:

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

{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 4316 of file json.hpp.

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

helper for exception-safe object creation

Definition at line 699 of file json.hpp.

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

range-rbegin-rend.svg
Illustration from cppreference.com

Constant.

This function helps basic_json satisfying the ReversibleContainer requirements:

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

{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 4345 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::dump ( const int  indent = -1) const
inline

serialization

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

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
Returns
string containing the serialization of the JSON value

Linear.

{The following example shows the effect of different indent 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

Definition at line 2079 of file json.hpp.

Here is the caller graph for this function:

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::dump ( std::ostream &  o,
const bool  pretty_print,
const unsigned int  indent_step,
const unsigned int  current_indent = 0 
) const
inlineprivate

internal implementation of the serialization function

This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively. Note that

  • strings and object keys are escaped using escape_string()
  • integer numbers are converted implicitly via operator<<
  • floating-point numbers are converted to a string using "%g" format
Parameters
[out]ostream to write to
[in]pretty_printwhether the output shall be pretty-printed
[in]indent_stepthe indent level
[in]current_indentthe current indent level (only used internally)

Definition at line 5929 of file json.hpp.

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

checks whether the container is empty

Checks if a JSON value has no elements.

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
object result of function object_t::empty()
array result of function array_t::empty()
Constant, as long as array_t and object_t satisfy the Container concept; that is, their empty() functions have constant complexity.

This function helps basic_json satisfying the Container requirements:

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

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

See also
size() – returns the number of elements
Since
version 1.0.0

Definition at line 4422 of file json.hpp.

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

returns an iterator to one past the last element

Returns an iterator to one past the last element.

range-begin-end.svg
Illustration from cppreference.com
Returns
iterator one past the last element

Constant.

This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.

{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 4172 of file json.hpp.

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

returns a const iterator to one past the last element

Returns a const iterator to one past the last element.

range-begin-end.svg
Illustration from cppreference.com
Returns
const iterator one past the last element

Constant.

This function helps basic_json satisfying the Container requirements:

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

{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 4182 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class InteratorType , typename std::enable_if< std::is_same< InteratorType, typename basic_json_t::iterator >::value orstd::is_same< InteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0>
InteratorType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase ( InteratorType  pos)
inline

remove element given an iterator

Removes the element specified by iterator pos. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.

If called on a primitive type other than null, the resulting JSON value will be null.

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
InteratorTypean iterator or const_iterator
Postcondition
Invalidates iterators and references at or after the point of the erase, including the end() iterator.
Exceptions
std::domain_errorif called on a null value; example: "cannot use erase() with null"
std::domain_errorif called on an iterator which does not belong to the current JSON value; example: "iterator does not fit current value"
std::out_of_rangeif called on a primitive type with invalid iterator (i.e., any iterator which is not begin()); example: "iterator out of range"

The complexity depends on the type:

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

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

See also
erase(InteratorType, InteratorType) – 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 3733 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class InteratorType , typename std::enable_if< std::is_same< InteratorType, typename basic_json_t::iterator >::value orstd::is_same< InteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0>
InteratorType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase ( InteratorType  first,
InteratorType  last 
)
inline

remove elements given an iterator range

Removes the element specified by the range [first; last). The iterator first does not need to be dereferenceable if first == last: erasing an empty range is a no-op.

If called on a primitive type other than null, the resulting JSON value will be null.

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
InteratorTypean iterator or const_iterator
Postcondition
Invalidates iterators and references at or after the point of the erase, including the end() iterator.
Exceptions
std::domain_errorif called on a null value; example: "cannot use erase() with null"
std::domain_errorif called on iterators which does not belong to the current JSON value; example: "iterators do not fit current value"
std::out_of_rangeif called on a primitive type with invalid iterators (i.e., if first != begin() and last != end()); example: "iterators out of range"

The complexity depends on the type:

  • 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: linear in the length of the string
  • other types: constant

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

See also
erase(InteratorType) – 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 3841 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase ( const typename object_t::key_type &  key)
inline

remove element from a JSON object given a key

Removes elements from a JSON object with the key value key.

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
std::domain_errorwhen called on a type other than JSON object; example: "cannot use erase() with null"

log(size()) + count(key)

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

See also
erase(InteratorType) – removes the element at a given position
erase(InteratorType, InteratorType) – 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 3928 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::erase ( const size_type  idx)
inline

remove element from a JSON array given an index

Removes element from a JSON array at the index idx.

Parameters
[in]idxindex of the element to remove
Exceptions
std::domain_errorwhen called on a type other than JSON array; example: "cannot use erase() with null"
std::out_of_rangewhen idx >= size(); example: "index out of range"

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

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

See also
erase(InteratorType) – removes the element at a given position
erase(InteratorType, InteratorType) – 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 3966 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::escape_string ( const string_t s)
inlinestaticprivate

escape a string

Escape a string by replacing certain special characters by a sequence of an escape character (backslash) and another character and other control characters by a sequence of "\u" followed by a four-digit hex representation.

Parameters
[in]sthe string to escape
Returns
the escaped string

Linear in the length of string s.

Definition at line 5806 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static std::size_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::extra_space ( const string_t s)
inlinestaticprivatenoexcept

calculates the extra space to escape a JSON string

Parameters
[in]sthe string to escape
Returns
the number of characters required to escape string s

Linear in the length of string s.

Definition at line 5757 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::find ( typename object_t::key_type  key)
inline

find an element in a JSON object

Finds an element in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, end() is returned.

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, past-the-end (see end()) iterator is returned.

Logarithmic in the size of the JSON object.

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

Since
version 1.0.0

Definition at line 4012 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::find ( typename object_t::key_type  key) const
inline

find an element in a JSON object

find an element in a JSON object Finds an element in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, end() is returned.

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, past-the-end (see end()) iterator is returned.

Logarithmic in the size of the JSON object.

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

Since
version 1.0.0

Definition at line 4029 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::front ( )
inline

access the first element

Returns a reference to the first element in the container. For a JSON container c, the expression c.front() is equivalent to *c.begin().

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

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
std::out_of_rangewhen called on null value

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

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

Definition at line 3623 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::front ( ) const
inline

access the first element

Returns a reference to the first element in the container. For a JSON container c, the expression c.front() is equivalent to *c.begin().

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

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
std::out_of_rangewhen called on null value

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

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

Definition at line 3631 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename ValueType , typename std::enable_if< not std::is_pointer< ValueType >::value, int >::type = 0>
ValueType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get ( ) const
inline

get a value (explicit)

Explicit type conversion between the JSON value and a compatible value.

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
Returns
copy of the JSON value, converted to type ValueType
Exceptions
std::domain_errorin case passed type ValueType is incompatible to JSON; example: "type must be object, but is null"

Linear in the size of the JSON value.

{The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers\, (2) A JSON array can be converted to a standard std::vector<short>\, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string\, json>.,get__ValueType_const}

See also
operator ValueType() const for implicit conversion
get() for pointer-member access
Since
version 1.0.0

Definition at line 2789 of file json.hpp.

Here is the caller graph for this function:

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get ( )
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

Constant.

{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.,get__PointerType}

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

Definition at line 2824 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
constexpr const PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get ( ) const
inlinenoexcept

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

Constant.

{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.,get__PointerType}

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

Definition at line 2838 of file json.hpp.

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

returns the allocator associated with the container

Definition at line 234 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class T , typename std::enable_if< std::is_convertible< typename object_t::key_type, typename T::key_type >::value andstd::is_convertible< basic_json_t, typename T::mapped_type >::value, int >::type = 0>
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl ( T *  ) const
inlineprivate

get an object (explicit)

Definition at line 2463 of file json.hpp.

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

get an object (explicit)

Definition at line 2477 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class T , typename std::enable_if< std::is_convertible< basic_json_t, typename T::value_type >::value andnot std::is_same< basic_json_t, typename T::value_type >::value andnot std::is_arithmetic< T >::value andnot std::is_convertible< std::string, T >::value andnot has_mapped_type< T >::value, int >::type = 0>
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl ( T *  ) const
inlineprivate

get an array (explicit)

Definition at line 2499 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class T , typename std::enable_if< std::is_convertible< basic_json_t, T >::value andnot std::is_same< basic_json_t, T >::value, int >::type = 0>
std::vector<T> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl ( std::vector< T > *  ) const
inlineprivate

get an array (explicit)

Definition at line 2524 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class T , typename std::enable_if< std::is_same< basic_json, typename T::value_type >::value andnot has_mapped_type< T >::value, int >::type = 0>
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl ( T *  ) const
inlineprivate

get an array (explicit)

Definition at line 2550 of file json.hpp.

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

get an array (explicit)

Definition at line 2564 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T , typename std::enable_if< std::is_convertible< string_t, T >::value, int >::type = 0>
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl ( T *  ) const
inlineprivate

get a string (explicit)

Definition at line 2582 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value, int >::type = 0>
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_impl ( T *  ) const
inlineprivate

get a number (explicit)

Definition at line 2600 of file json.hpp.

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

get a boolean (explicit)

Definition at line 2627 of file json.hpp.

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

get a pointer to the value (object)

Definition at line 2635 of file json.hpp.

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

get a pointer to the value (object)

Definition at line 2641 of file json.hpp.

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

get a pointer to the value (array)

Definition at line 2647 of file json.hpp.

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

get a pointer to the value (array)

Definition at line 2653 of file json.hpp.

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

get a pointer to the value (string)

Definition at line 2659 of file json.hpp.

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

get a pointer to the value (string)

Definition at line 2665 of file json.hpp.

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

get a pointer to the value (boolean)

Definition at line 2671 of file json.hpp.

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

get a pointer to the value (boolean)

Definition at line 2677 of file json.hpp.

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

get a pointer to the value (integer number)

Definition at line 2683 of file json.hpp.

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

get a pointer to the value (integer number)

Definition at line 2689 of file json.hpp.

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

get a pointer to the value (unsigned number)

Definition at line 2695 of file json.hpp.

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

get a pointer to the value (unsigned number)

Definition at line 2701 of file json.hpp.

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

get a pointer to the value (floating-point number)

Definition at line 2707 of file json.hpp.

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

get a pointer to the value (floating-point number)

Definition at line 2713 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0>
PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ptr ( )
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.
Returns
pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise

Constant.

{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.,get_ptr}

Since
version 1.0.0

Definition at line 2873 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::valueand std::is_const< typename std::remove_pointer< PointerType >::type >::value, int >::type = 0>
constexpr const PointerType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ptr ( ) const
inlinenoexcept

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.
Returns
pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise

Constant.

{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.,get_ptr}

Since
version 1.0.0

Definition at line 2888 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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 >::get_ref ( )
inline

get a reference value (implicit)

Implict 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.
Returns
reference to the internally stored JSON value if the requested reference type ReferenceType fits to the JSON value; throws std::domain_error otherwise
Exceptions
std::domain_errorin case passed type ReferenceType is incompatible with the stored JSON value

Constant.

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

Since
version 1.1.0

Definition at line 2924 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::valueand std::is_const< typename std::remove_reference< ReferenceType >::type >::value, int >::type = 0>
ReferenceType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::get_ref ( ) const
inline

get a reference value (implicit)

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

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.
Returns
reference to the internally stored JSON value if the requested reference type ReferenceType fits to the JSON value; throws std::domain_error otherwise
Exceptions
std::domain_errorin case passed type ReferenceType is incompatible with the stored JSON value

Constant.

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

Since
version 1.1.0

Definition at line 2939 of file json.hpp.

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

helper function to implement get_ref()

This funcion 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
std::domain_errorif ReferenceType does not match underlying value type of the current JSON

Definition at line 2730 of file json.hpp.

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

inserts element

Inserts element val before iterator pos.

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
std::domain_errorif called on JSON values other than arrays; example: "cannot use insert() with string"
std::domain_errorif pos is not an iterator of *this; example: "iterator does not fit current value"

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

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

Since
version 1.0.0

Definition at line 4824 of file json.hpp.

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

inserts element

inserts element Inserts element val before iterator pos.

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
std::domain_errorif called on JSON values other than arrays; example: "cannot use insert() with string"
std::domain_errorif pos is not an iterator of *this; example: "iterator does not fit current value"

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

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

Since
version 1.0.0

Definition at line 4851 of file json.hpp.

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

inserts elements

Inserts cnt copies of val before iterator pos.

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
std::domain_errorif called on JSON values other than arrays; example: "cannot use insert() with string"
std::domain_errorif pos is not an iterator of *this; example: "iterator does not fit current value"

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

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

Since
version 1.0.0

Definition at line 4880 of file json.hpp.

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

inserts elements

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

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
std::domain_errorif called on JSON values other than arrays; example: "cannot use insert() with string"
std::domain_errorif pos is not an iterator of *this; example: "iterator does not fit current value"
std::domain_errorif first and last do not belong to the same JSON value; example: "iterators do not fit"
std::domain_errorif 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

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

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

Since
version 1.0.0

Definition at line 4933 of file json.hpp.

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

inserts elements

Inserts elements from initializer list ilist before iterator pos.

Parameters
[in]positerator before which the content will be inserted; may be the end() iterator
[in]ilistinitializer list to insert the values from
Exceptions
std::domain_errorif called on JSON values other than arrays; example: "cannot use insert() with string"
std::domain_errorif 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

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

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

Since
version 1.0.0

Definition at line 4991 of file json.hpp.

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

return whether value is an array

This function returns true iff the JSON value is an array.

Returns
true if type is array, false otherwise.

Constant.

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

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

Since
version 1.0.0

Definition at line 2373 of file json.hpp.

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

return whether value is a boolean

This function returns true iff the JSON value is a boolean.

Returns
true if type is boolean, false otherwise.

Constant.

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

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

Since
version 1.0.0

Definition at line 2214 of file json.hpp.

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

return whether value is discarded

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

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.

Constant.

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

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

Since
version 1.0.0

Definition at line 2422 of file json.hpp.

Here is the caller graph for this function:

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

return whether value is null

This function returns true iff the JSON value is null.

Returns
true if type is null, false otherwise.

Constant.

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

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

Since
version 1.0.0

Definition at line 2192 of file json.hpp.

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

return whether value is a number

This function returns true iff the JSON value is a number. This includes both integer and floating-point values.

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

Constant.

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

{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 2244 of file json.hpp.

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

return whether value is a floating-point number

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

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

Constant.

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

{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 2329 of file json.hpp.

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

return whether value is an integer number

This function returns true iff the JSON value is an integer or unsigned integer number. This excludes floating-point values.

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

Constant.

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

{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 2273 of file json.hpp.

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

return whether value is an unsigned integer number

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

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

Constant.

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

{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 2301 of file json.hpp.

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

return whether value is an object

This function returns true iff the JSON value is an object.

Returns
true if type is object, false otherwise.

Constant.

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

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

Since
version 1.0.0

Definition at line 2351 of file json.hpp.

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

return whether type is primitive

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

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

Constant.

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

{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
Since
version 1.0.0

Definition at line 2143 of file json.hpp.

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

return whether value is a string

This function returns true iff the JSON value is a string.

Returns
true if type is string, false otherwise.

Constant.

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

{The following code exemplifies is_string() for all JSON types.,is_string}

Since
version 1.0.0

Definition at line 2395 of file json.hpp.

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

return whether type is structured

This function returns true iff the JSON type is structured (array or object).

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

Constant.

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

{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 2170 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static iteration_proxy<iterator> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::iterator_wrapper ( reference  cont)
inlinestatic

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.

Note
The name of this function is not yet final and may change in the future.

Definition at line 4366 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static iteration_proxy<const_iterator> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::iterator_wrapper ( const_reference  cont)
inlinestatic

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.

Note
The name of this function is not yet final and may change in the future.

Definition at line 4374 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::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())
object result of function object_t::max_size()
array result of function array_t::max_size()
Constant, as long as array_t and object_t satisfy the Container concept; that is, their max_size() functions have constant complexity.

This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of returning b.size() where b is the largest possible JSON value.

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

See also
size() – returns the number of elements
Since
version 1.0.0

Definition at line 4551 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::object ( std::initializer_list< basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > >  init = std::initializer_list<basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >>())
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(std::initializer_list<basic_json>), 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(std::initializer_list<basic_json>, bool, value_t).
Parameters
[in]initinitializer list to create an object from (optional)
Returns
JSON object value
Exceptions
std::domain_errorif init is not a pair whose first elements are strings; thrown by basic_json(std::initializer_list<basic_json>, bool, value_t)

Linear in the size of init.

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

See also
basic_json(std::initializer_list<basic_json>, bool, value_t)create a JSON value from an initializer list
array(std::initializer_list<basic_json>)create a JSON array value from an initializer list
Since
version 1.0.0

Definition at line 1667 of file json.hpp.

Here is the caller graph for this function:

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

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

Constant.

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

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

Since
version 1.0.0

Definition at line 2445 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename ValueType , typename std::enable_if< not std::is_pointer< ValueType >::valueand not std::is_same< ValueType, typename string_t::value_type >::valueand not std::is_same< ValueType, std::initializer_list< typename string_t::value_type >>::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator ValueType ( ) const
inline

get a value (implicit)

Implicit type conversion between the JSON value and a compatible value. The call is realized by calling get() const.

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
std::domain_errorin case passed type ValueType is incompatible to JSON, thrown by get() const

Linear in the size of the JSON value.

{The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers\, (2) A JSON array can be converted to a standard std::vector<short>\, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string\, json>.,operator__ValueType}

Since
version 1.0.0

Definition at line 2981 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &&  val)
inline

add an object to an array

add an object to an array Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.

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

Amortized constant.

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

Since
version 1.0.0

Definition at line 4712 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &  val)
inline

add an object to an array

add an object to an array Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.

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

Amortized constant.

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

Since
version 1.0.0

Definition at line 4746 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator+= ( const typename object_t::value_type &  val)
inline

add an object to an object

add an object to an object Inserts the given element val to the JSON object. If the function is called on a JSON null value, an empty object is created before inserting val.

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

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

{The example shows how push_back() and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.,push_back__object_t__value}

Since
version 1.0.0

Definition at line 4796 of file json.hpp.

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

Linear.

This function helps basic_json satisfying the Container requirements:

  • The complexity is linear.

{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 1982 of file json.hpp.

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

access specified array element

Returns a reference to the element at specified location idx.

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
std::domain_errorif JSON is not an array or null; example: "cannot use operator[] with string"

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

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

Since
version 1.0.0

Definition at line 3206 of file json.hpp.

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

access specified array element

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

Parameters
[in]idxindex of the element to access
Returns
const reference to the element at index idx
Exceptions
std::domain_errorif JSON is not an array; example: "cannot use operator[] with null"

Constant.

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

Since
version 1.0.0

Definition at line 3252 of file json.hpp.

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

access specified object element

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

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
std::domain_errorif JSON is not an object or null; example: "cannot use operator[] with string"

Logarithmic in the size of the container.

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

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 3293 of file json.hpp.

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

read-only access specified object element

Returns a const reference to the element at with specified key key. No bounds checking is performed.

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
Exceptions
std::domain_errorif JSON is not an object; example: "cannot use operator[] with null"

Logarithmic in the size of the container.

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

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 3341 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T , std::size_t n>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] ( T *(&)  key[n])
inline

access specified object element

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

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
std::domain_errorif JSON is not an object or null; example: "cannot use operator[] with string"

Logarithmic in the size of the container.

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

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 3384 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T , std::size_t n>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] ( T *(&)  key[n]) const
inline

read-only access specified object element

Returns a const reference to the element at with specified key key. No bounds checking is performed.

Warning
If the element with key key does not exist, the behavior is undefined.
Note
This function is required for compatibility reasons with Clang.
Parameters
[in]keykey of the element to access
Returns
const reference to the element at key key
Exceptions
std::domain_errorif JSON is not an object; example: "cannot use operator[] with null"

Logarithmic in the size of the container.

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

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 3419 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<typename T >
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::operator[] ( T *  key)
inline

access specified object element

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

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
std::domain_errorif JSON is not an object or null; example: "cannot use operator[] with string"

Logarithmic in the size of the container.

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

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 3452 of file json.hpp.

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

read-only access specified object element

Returns a const reference to the element at with specified key key. No bounds checking is performed.

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
Exceptions
std::domain_errorif JSON is not an object; example: "cannot use operator[] with null"

Logarithmic in the size of the container.

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

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 3501 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parse ( const string_t s,
parser_callback_t  cb = nullptr 
)
inlinestatic

deserialize from string

Parameters
[in]sstring to read a serialized JSON value from
[in]cba parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)
Returns
result of the deserialization

Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.

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

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

See also
parse(std::istream&, parser_callback_t) for a version that reads from an input stream
Since
version 1.0.0

Definition at line 5638 of file json.hpp.

Here is the caller graph for this function:

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parse ( std::istream &  i,
parser_callback_t  cb = nullptr 
)
inlinestatic

deserialize from stream

Parameters
[in,out]istream to read a serialized JSON value from
[in]cba parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)
Returns
result of the deserialization

Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.

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

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

See also
parse(const string_t&, parser_callback_t) for a version that reads from a string
Since
version 1.0.0

Definition at line 5667 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::parse ( std::istream &&  i,
parser_callback_t  cb = nullptr 
)
inlinestatic

deserialize from stream

Parameters
[in,out]istream to read a serialized JSON value from
[in]cba parser callback function of type parser_callback_t which is used to control the deserialization by filtering unwanted values (optional)
Returns
result of the deserialization

Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.

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

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

See also
parse(const string_t&, parser_callback_t) for a version that reads from a string
Since
version 1.0.0

Definition at line 5675 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::push_back ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &&  val)
inline

add an object to an array

Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.

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

Amortized constant.

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

Since
version 1.0.0

Definition at line 4686 of file json.hpp.

Here is the caller graph for this function:

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

add an object to an array

add an object to an array Appends the given element val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending val.

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

Amortized constant.

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

Since
version 1.0.0

Definition at line 4722 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::push_back ( const typename object_t::value_type &  val)
inline

add an object to an object

Inserts the given element val to the JSON object. If the function is called on a JSON null value, an empty object is created before inserting val.

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

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

{The example shows how push_back() and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.,push_back__object_t__value}

Since
version 1.0.0

Definition at line 4772 of file json.hpp.

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

returns an iterator to the reverse-beginning

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

range-rbegin-rend.svg
Illustration from cppreference.com

Constant.

This function helps basic_json satisfying the ReversibleContainer requirements:

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

{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 4242 of file json.hpp.

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

range-rbegin-rend.svg
Illustration from cppreference.com

Constant.

This function helps basic_json satisfying the ReversibleContainer requirements:

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

{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 4250 of file json.hpp.

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

returns an iterator to the reverse-end

Returns an iterator to the reverse-end; that is, one before the first element.

range-rbegin-rend.svg
Illustration from cppreference.com

Constant.

This function helps basic_json satisfying the ReversibleContainer requirements:

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

{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 4279 of file json.hpp.

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

range-rbegin-rend.svg
Illustration from cppreference.com

Constant.

This function helps basic_json satisfying the ReversibleContainer requirements:

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

{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 4287 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::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
object result of function object_t::size()
array result of function array_t::size()
Constant, as long as array_t and object_t satisfy the Container concept; that is, their size() functions have constant complexity.

This function helps basic_json satisfying the Container requirements:

  • The complexity is constant.
  • Has the semantics of std::distance(begin(), end()).

{The following code calls size() on the different value types.,size}

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 4485 of file json.hpp.

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

Constant.

{The example below shows how JSON values can be swapped with swap().,swap__reference}

Since
version 1.0.0

Definition at line 5029 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap ( array_t other)
inline

exchanges the values

Exchanges the contents of a JSON array with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.

Parameters
[in,out]otherarray to exchange the contents with
Exceptions
std::domain_errorwhen JSON value is not an array; example: "cannot use swap() with string"

Constant.

{The example below shows how arrays can be swapped with swap().,swap__array_t}

Since
version 1.0.0

Definition at line 5060 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap ( object_t other)
inline

exchanges the values

Exchanges the contents of a JSON object with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.

Parameters
[in,out]otherobject to exchange the contents with
Exceptions
std::domain_errorwhen JSON value is not an object; example: "cannot use swap() with string"

Constant.

{The example below shows how objects can be swapped with swap().,swap__object_t}

Since
version 1.0.0

Definition at line 5094 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::swap ( string_t other)
inline

exchanges the values

Exchanges the contents of a JSON string with those of other. Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.

Parameters
[in,out]otherstring to exchange the contents with
Exceptions
std::domain_errorwhen JSON value is not a string; example: "cannot use swap() with boolean"

Constant.

{The example below shows how strings can be swapped with swap().,swap__string_t}

Since
version 1.0.0

Definition at line 5128 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
constexpr value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::type ( ) const
inlinenoexcept

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

Constant.

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

{The following code exemplifies type() for all JSON types.,type}

Since
version 1.0.0

Definition at line 2113 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::type_name ( ) const
inlineprivatenoexcept

return the type as string

Definition at line 5728 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
template<class ValueType , typename std::enable_if< std::is_convertible< basic_json_t, ValueType >::value, int >::type = 0>
ValueType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::value ( const typename object_t::key_type &  key,
ValueType  default_value 
) const
inline

access specified object element with default value

Returns either a copy of an object's element at the specified key key or a given default value if no element with key key exists.

The function is basically equivalent to executing

try {
return at(key);
} catch(std::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
std::domain_errorif JSON is not an object; example: "cannot use value() with null"

Logarithmic in the size of the container.

{The example below shows how object elements can be queried with a default value.,basic_json__value}

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 3568 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::value ( const typename object_t::key_type &  key,
const char *  default_value 
) const
inline

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(std::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
std::domain_errorif JSON is not an object; example: "cannot use value() with null"

Logarithmic in the size of the container.

{The example below shows how object elements can be queried with a default value.,basic_json__value}

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 3594 of file json.hpp.

Friends And Related Function Documentation

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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

Linear.

{The example demonstrates comparing several JSON types.,operator__notequal}

Since
version 1.0.0

Definition at line 5338 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
bool operator!= ( const_reference  v,
std::nullptr_t   
)
friend

comparison: not equal

The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call not v.is_null().

Parameters
[in]vJSON value to consider
Returns
whether v is not null

Constant.

{The example compares several JSON types to the null pointer. ,operator__notequal__nullptr_t}

Since
version 1.0.0

Definition at line 5361 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
bool operator!= ( std::nullptr_t  ,
const_reference  v 
)
friend

comparison: not equal

comparison: not equal The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call not v.is_null().

Parameters
[in]vJSON value to consider
Returns
whether v is not null

Constant.

{The example compares several JSON types to the null pointer. ,operator__notequal__nullptr_t}

Since
version 1.0.0

Definition at line 5370 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
bool operator< ( const value_t  lhs,
const value_t  rhs 
)
friend

comparison operator for JSON types

Returns an ordering that is similar to Python:

  • order: null < boolean < number < object < array < string
  • furthermore, each type is not smaller than itself
Since
version 1.0.0

Definition at line 5162 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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

Linear.

{The example demonstrates comparing several JSON types.,operator__less}

Since
version 1.0.0

Definition at line 5399 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
std::ostream& operator<< ( std::ostream &  o,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &  j 
)
friend

serialize to stream

Serialize the given JSON value j to the output stream o. The JSON value will be serialized using the dump member function. The indentation of the output can be controlled with the member variable width of the output stream o. For instance, using the manipulator std::setw(4) on o sets the indentation level to 4 and the serialization result is the same as calling dump(4).

Parameters
[in,out]ostream to serialize to
[in]jJSON value to serialize
Returns
the stream o

Linear.

{The example below shows the serialization with different parameters to width to adjust the indentation level.,operator_serialize}

Since
version 1.0.0

Definition at line 5581 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
std::istream& operator<< ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &  j,
std::istream &  i 
)
friend

deserialize from stream

Deserializes an input stream to a JSON value.

Parameters
[in,out]iinput stream to read a serialized JSON value from
[in,out]jJSON value to write the deserialized input to
Exceptions
std::invalid_argumentin case of parse errors

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.

{The example below shows how a JSON value is constructed by reading a serialization from a stream.,operator_deserialize}

See also
parse(std::istream&, parser_callback_t) for a variant with a parser callback function to filter values while parsing
Since
version 1.0.0

Definition at line 5703 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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

Linear.

{The example demonstrates comparing several JSON types.,operator__greater}

Since
version 1.0.0

Definition at line 5500 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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.
  • Integer and floating-point numbers are automatically converted before comparison. Floating-point numbers are compared indirectly: two floating-point numbers f1 and f2 are considered equal if neither f1 > f2 nor f2 > f1 holds.
  • Two JSON null values are equal.
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are equal

Linear.

{The example demonstrates comparing several JSON types.,operator__equal}

Since
version 1.0.0

Definition at line 5209 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
bool operator== ( const_reference  v,
std::nullptr_t   
)
friend

comparison: equal

The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call v.is_null().

Parameters
[in]vJSON value to consider
Returns
whether v is null

Constant.

{The example compares several JSON types to the null pointer. ,operator__equal__nullptr_t}

Since
version 1.0.0

Definition at line 5308 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
bool operator== ( std::nullptr_t  ,
const_reference  v 
)
friend

comparison: equal

comparison: equal The functions compares the given JSON value against a null pointer. As the null pointer can be used to initialize a JSON value to null, a comparison of JSON value v with a null pointer should be equivalent to call v.is_null().

Parameters
[in]vJSON value to consider
Returns
whether v is null

Constant.

{The example compares several JSON types to the null pointer. ,operator__equal__nullptr_t}

Since
version 1.0.0

Definition at line 5317 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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

Linear.

{The example demonstrates comparing several JSON types.,operator__lessequal}

Since
version 1.0.0

Definition at line 5522 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
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

Linear.

{The example demonstrates comparing several JSON types.,operator__greaterequal}

Since
version 1.0.0

Definition at line 5544 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
std::ostream& operator>> ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &  j,
std::ostream &  o 
)
friend

serialize to stream

serialize to stream Serialize the given JSON value j to the output stream o. The JSON value will be serialized using the dump member function. The indentation of the output can be controlled with the member variable width of the output stream o. For instance, using the manipulator std::setw(4) on o sets the indentation level to 4 and the serialization result is the same as calling dump(4).

Parameters
[in,out]ostream to serialize to
[in]jJSON value to serialize
Returns
the stream o

Linear.

{The example below shows the serialization with different parameters to width to adjust the indentation level.,operator_serialize}

Since
version 1.0.0

Definition at line 5599 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
std::istream& operator>> ( std::istream &  i,
basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType > &  j 
)
friend

deserialize from stream

deserialize from stream Deserializes an input stream to a JSON value.

Parameters
[in,out]iinput stream to read a serialized JSON value from
[in,out]jJSON value to write the deserialized input to
Exceptions
std::invalid_argumentin case of parse errors

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.

{The example below shows how a JSON value is constructed by reading a serialization from a stream.,operator_deserialize}

See also
parse(std::istream&, parser_callback_t) for a variant with a parser callback function to filter values while parsing
Since
version 1.0.0

Definition at line 5713 of file json.hpp.

Member Data Documentation

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::m_type = value_t::null
private

the type of the current element

Definition at line 6088 of file json.hpp.

template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
json_value nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >::m_value = {}
private

the value of the current element

Definition at line 6091 of file json.hpp.


The documentation for this class was generated from the following file: