JSON for Modern C++  3.0
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > Class Template Reference

JSON. More...

#include <json.hpp>

Collaboration diagram for nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >:

Classes

class  const_iterator
 a const random access iterator for the basic_json class More...
 
class  const_reverse_iterator
 a const reverse random access iterator for the basic_json class More...
 
union  internal_iterator
 an iterator value More...
 
class  iterator
 a random access iterator for the basic_json class More...
 
union  json_value
 a JSON value More...
 
class  lexer
 lexical analysis More...
 
class  parser
 syntax analysis More...
 
class  reverse_iterator
 a reverse random access iterator for the basic_json class 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_float
}
 JSON value type enumeration. More...
 
using value_type = basic_json
 the type of elements in a basic_json container More...
 
using reference = basic_json &
 the type of an element reference More...
 
using const_reference = const basic_json &
 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 = Allocator< basic_json >
 the allocator type More...
 
using pointer = basic_json *
 the type of an element pointer More...
 
using const_pointer = const basic_json *
 the type of an element const pointer More...
 
using iterator = basic_json::iterator
 an iterator for a basic_json container More...
 
using const_iterator = basic_json::const_iterator
 a const iterator for a basic_json container More...
 
using reverse_iterator = basic_json::reverse_iterator
 a reverse iterator for a basic_json container More...
 
using const_reverse_iterator = basic_json::const_reverse_iterator
 a const reverse iterator for a basic_json container More...
 
using object_t = ObjectType< StringType, basic_json >
 a type for an object More...
 
using array_t = ArrayType< 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_float_t = NumberFloatType
 a type for a number (floating-point) More...
 
using list_init_t = std::initializer_list< basic_json >
 a type for list initialization More...
 

Public Member Functions

allocator_type get_allocator () const
 returns the allocator associated with the container More...
 
 basic_json (const value_t value)
 create an empty value with a given type More...
 
 basic_json () noexcept=default
 create a null object (implicitly) More...
 
 basic_json (std::nullptr_t) noexcept
 create a null object (explicitly) More...
 
 basic_json (const object_t &value)
 create an object (explicit) More...
 
template<class V , typename std::enable_if< std::is_constructible< typename object_t::key_type, typename V::key_type >::value andstd::is_constructible< basic_json, typename V::mapped_type >::value, int >::type = 0>
 basic_json (const V &value)
 create an object (implicit) More...
 
 basic_json (const array_t &value)
 create an array (explicit) More...
 
template<class V , typename std::enable_if< not std::is_same< V, basic_json::iterator >::value andnot std::is_same< V, basic_json::const_iterator >::value andnot std::is_same< V, basic_json::reverse_iterator >::value andnot std::is_same< V, basic_json::const_reverse_iterator >::value andnot std::is_same< V, typename array_t::iterator >::value andnot std::is_same< V, typename array_t::const_iterator >::value andstd::is_constructible< basic_json, typename V::value_type >::value, int >::type = 0>
 basic_json (const V &value)
 create an array (implicit) More...
 
 basic_json (const string_t &value)
 create a string (explicit) More...
 
 basic_json (const typename string_t::value_type *value)
 create a string (explicit) More...
 
template<class V , typename std::enable_if< std::is_constructible< string_t, V >::value, int >::type = 0>
 basic_json (const V &value)
 create a string (implicit) More...
 
 basic_json (boolean_t value)
 create a boolean (explicit) More...
 
 basic_json (const number_integer_t &value)
 create an integer number (explicit) More...
 
template<typename T , typename std::enable_if< std::is_constructible< number_integer_t, T >::value andstd::numeric_limits< T >::is_integer, T >::type = 0>
 basic_json (const T value) noexcept
 create an integer number (implicit) More...
 
 basic_json (const number_float_t &value)
 create a floating-point number (explicit) More...
 
template<typename T , typename = typename std::enable_if< std::is_constructible<number_float_t, T>::value and std::is_floating_point<T>::value>::type>
 basic_json (const T value) noexcept
 create a floating-point number (implicit) More...
 
 basic_json (list_init_t l, bool type_deduction=true, value_t manual_type=value_t::array)
 create a container (array or object) from an initializer list 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 () noexcept
 destructor More...
 
string_t dump (const int indent=-1) const noexcept
 serialization More...
 
value_t type () const noexcept
 return the type of the object (explicit) More...
 
bool is_null () const noexcept
 
bool is_boolean () const noexcept
 
bool is_number () const noexcept
 
bool is_object () const noexcept
 
bool is_array () const noexcept
 
bool is_string () const noexcept
 
 operator value_t () const noexcept
 return the type of the object (implicit) More...
 
template<typename T >
get () const
 get a value (explicit) More...
 
template<typename T >
 operator T () const
 get a value (implicit) More...
 
reference at (size_type pos)
 access specified element with bounds checking More...
 
const_reference at (size_type pos) const
 access specified element with bounds checking More...
 
reference operator[] (size_type pos)
 access specified element More...
 
const_reference operator[] (size_type pos) const
 access specified element More...
 
reference at (const typename object_t::key_type &key)
 access specified element with bounds checking More...
 
const_reference at (const typename object_t::key_type &key) const
 access specified element with bounds checking More...
 
reference operator[] (const typename object_t::key_type &key)
 access specified element More...
 
const_reference operator[] (const typename object_t::key_type &key) const
 access specified element More...
 
template<typename T , size_t n>
reference operator[] (const T(&key)[n])
 access specified element (needed for clang) More...
 
template<typename T , size_t n>
const_reference operator[] (const T(&key)[n]) const
 access specified element (needed for clang) More...
 
size_type erase (const typename object_t::key_type &key)
 remove element from an object given a key More...
 
void erase (const size_type pos)
 remove element from an array given an index More...
 
iterator find (typename object_t::key_type key)
 find an element in an object More...
 
const_iterator find (typename object_t::key_type key) const
 find an element in an object More...
 
size_type count (typename object_t::key_type key) const
 returns the number of occurrences of a key in an object 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 a reverse iterator to the first element More...
 
const_reverse_iterator rbegin () const noexcept
 returns a const reverse iterator to the first element More...
 
reverse_iterator rend () noexcept
 returns a reverse iterator to one past the last element More...
 
const_reverse_iterator rend () const noexcept
 returns a const reverse iterator to one past the last element More...
 
const_reverse_iterator crbegin () const noexcept
 returns a const reverse iterator to the first element More...
 
const_reverse_iterator crend () const noexcept
 returns a const reverse iterator to one past the last element More...
 
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...
 
void clear () noexcept
 clears the contents More...
 
void push_back (basic_json &&value)
 add an object to an array More...
 
reference operator+= (basic_json &&value)
 add an object to an array More...
 
void push_back (const basic_json &value)
 add an object to an array More...
 
reference operator+= (const basic_json &value)
 add an object to an array More...
 
void push_back (const typename object_t::value_type &value)
 add an object to an object More...
 
reference operator+= (const typename object_t::value_type &value)
 add an object to an object 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)
 swaps the contents More...
 
void swap (object_t &other)
 swaps the contents More...
 
void swap (string_t &other)
 swaps the contents More...
 

Static Public Member Functions

static basic_json array (list_init_t l=list_init_t())
 explicitly create an array from an initializer list More...
 
static basic_json object (list_init_t l=list_init_t())
 explicitly create an object from an initializer list More...
 
static basic_json parse (const string_t &s)
 deserialize from string More...
 
static basic_json parse (std::istream &i)
 deserialize from stream 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, 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, typename T::value_type >::value andnot std::is_same< basic_json, 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 >::value andnot std::is_same< basic_json, 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
 
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...
 
boolean_t get_impl (boolean_t *) const
 get a boolean (explicit) More...
 
string_t type_name () const noexcept
 return the type as string More...
 
string_t dump (const bool prettyPrint, const unsigned int indentStep, const unsigned int currentIndent=0) const noexcept
 internal implementation of the serialization function More...
 

Static Private Member Functions

static string_t escape_string (const string_t &s) noexcept
 escape a string More...
 
template<typename T >
static bool approx (const T a, const T b)
 "equality" comparison for floating point numbers More...
 

Private Attributes

value_t m_type = value_t::null
 the type of the current element More...
 
bool m_final = false
 whether the type of JSON object may change later More...
 
json_value m_value = {}
 the value of the current element More...
 

Friends

bool operator< (const value_t lhs, const value_t rhs)
 comparison operator for JSON value types More...
 
bool operator== (const_reference lhs, const_reference rhs) noexcept
 comparison: equal More...
 
bool operator!= (const_reference lhs, const_reference rhs) 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...
 
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...
 
std::istream & operator>> (std::istream &i, basic_json &j)
 deserialize from stream More...
 
std::istream & operator<< (basic_json &j, std::istream &i)
 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >

Template Parameters
ObjectTypetype for JSON objects (std::map by default)
ArrayTypetype for JSON arrays (std::vector by default)
StringTypetype for JSON strings and object keys (std::string by default)
BooleanTypetype for JSON booleans (bool by default)
NumberIntegerTypetype for JSON integer numbers (int64_t by default)
NumberFloatTypetype for JSON floating-point numbers (double by default)
Allocatortype of the allocator to use (std::allocator by default)
Note
ObjectType trick from http://stackoverflow.com/a/9860911
See also
RFC 7159 http://rfc7159.net/rfc7159
ECMA 404 http://www.ecma-international.org/publications/standards/Ecma-404.htm

Definition at line 102 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::allocator_type = Allocator<basic_json>

Definition at line 146 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::array_t = ArrayType<basic_json>

Definition at line 192 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::boolean_t = BooleanType

Definition at line 196 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::const_pointer = const basic_json*

Definition at line 151 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::list_init_t = std::initializer_list<basic_json>

Definition at line 202 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::number_float_t = NumberFloatType

Definition at line 200 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::number_integer_t = NumberIntegerType

Definition at line 198 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::object_t = ObjectType<StringType, basic_json>

Definition at line 190 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::pointer = basic_json*

Definition at line 149 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::string_t = StringType

Definition at line 194 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
enum nlohmann::basic_json::value_t : uint8_t
strong
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_float 

number value (floating-point)

Definition at line 241 of file json.hpp.

241  : uint8_t
242  {
243  null,
244  object,
245  array,
246  string,
247  boolean,
248  number_integer,
249  number_float
250  };
static basic_json object(list_init_t l=list_init_t())
explicitly create an object from an initializer list
Definition: json.hpp:596
static basic_json array(list_init_t l=list_init_t())
explicitly create an array from an initializer list
Definition: json.hpp:590

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const value_t  value)
inline
Parameters
valuethe type to create an value of
Exceptions
std::bad_allocif allocation for object, array, or string fails.

Definition at line 344 of file json.hpp.

345  : m_type(value)
346  {
347  switch (m_type)
348  {
349  case (value_t::null):
350  {
351  break;
352  }
353 
354  case (value_t::object):
355  {
356  Allocator<object_t> alloc;
357  m_value.object = alloc.allocate(1);
358  alloc.construct(m_value.object);
359  break;
360  }
361 
362  case (value_t::array):
363  {
364  Allocator<array_t> alloc;
365  m_value.array = alloc.allocate(1);
366  alloc.construct(m_value.array);
367  break;
368  }
369 
370  case (value_t::string):
371  {
372  Allocator<string_t> alloc;
373  m_value.string = alloc.allocate(1);
374  alloc.construct(m_value.string, "");
375  break;
376  }
377 
378  case (value_t::boolean):
379  {
380  m_value.boolean = boolean_t(false);
381  break;
382  }
383 
385  {
387  break;
388  }
389 
390  case (value_t::number_float):
391  {
393  break;
394  }
395  }
396  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:196
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
boolean_t boolean
bolean
Definition: json.hpp:219
json_value m_value
the value of the current element
Definition: json.hpp:2203
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:198
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:200
array (ordered collection of values)
number_integer_t number_integer
number (integer)
Definition: json.hpp:221
number_float_t number_float
number (floating-point)
Definition: json.hpp:223
object (unordered set of name/value pairs)
number value (floating-point)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( std::nullptr_t  )
inlinenoexcept

Definition at line 405 of file json.hpp.

407  {}
value_t m_type
the type of the current element
Definition: json.hpp:2197
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const object_t value)
inline

Definition at line 410 of file json.hpp.

412  {
413  Allocator<object_t> alloc;
414  m_value.object = alloc.allocate(1);
415  alloc.construct(m_value.object, value);
416  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<class V , typename std::enable_if< std::is_constructible< typename object_t::key_type, typename V::key_type >::value andstd::is_constructible< basic_json, typename V::mapped_type >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const V &  value)
inline

Definition at line 424 of file json.hpp.

426  {
427  Allocator<object_t> alloc;
428  m_value.object = alloc.allocate(1);
429  using std::begin;
430  using std::end;
431  alloc.construct(m_value.object, begin(value), end(value));
432  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:1261
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:1294
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const array_t value)
inline

Definition at line 435 of file json.hpp.

437  {
438  Allocator<array_t> alloc;
439  m_value.array = alloc.allocate(1);
440  alloc.construct(m_value.array, value);
441  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<class V , typename std::enable_if< not std::is_same< V, basic_json::iterator >::value andnot std::is_same< V, basic_json::const_iterator >::value andnot std::is_same< V, basic_json::reverse_iterator >::value andnot std::is_same< V, basic_json::const_reverse_iterator >::value andnot std::is_same< V, typename array_t::iterator >::value andnot std::is_same< V, typename array_t::const_iterator >::value andstd::is_constructible< basic_json, typename V::value_type >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const V &  value)
inline

Definition at line 454 of file json.hpp.

456  {
457  Allocator<array_t> alloc;
458  m_value.array = alloc.allocate(1);
459  using std::begin;
460  using std::end;
461  alloc.construct(m_value.array, begin(value), end(value));
462  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:1261
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:1294
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const string_t value)
inline

Definition at line 465 of file json.hpp.

467  {
468  Allocator<string_t> alloc;
469  m_value.string = alloc.allocate(1);
470  alloc.construct(m_value.string, value);
471  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
json_value m_value
the value of the current element
Definition: json.hpp:2203
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const typename string_t::value_type *  value)
inline

Definition at line 474 of file json.hpp.

476  {
477  Allocator<string_t> alloc;
478  m_value.string = alloc.allocate(1);
479  alloc.construct(m_value.string, value);
480  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
json_value m_value
the value of the current element
Definition: json.hpp:2203
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<class V , typename std::enable_if< std::is_constructible< string_t, V >::value, int >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const V &  value)
inline

Definition at line 487 of file json.hpp.

488  : basic_json(string_t(value))
489  {}
StringType string_t
a type for a string
Definition: json.hpp:194
basic_json() noexcept=default
create a null object (implicitly)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( boolean_t  value)
inline

Definition at line 492 of file json.hpp.

493  : m_type(value_t::boolean), m_value(value)
494  {}
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const number_integer_t value)
inline

Definition at line 497 of file json.hpp.

499  {}
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T , typename std::enable_if< std::is_constructible< number_integer_t, T >::value andstd::numeric_limits< T >::is_integer, T >::type = 0>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const T  value)
inlinenoexcept

Definition at line 507 of file json.hpp.

509  {}
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:198
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const number_float_t value)
inline

Definition at line 512 of file json.hpp.

514  {}
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
number value (floating-point)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T , typename = typename std::enable_if< std::is_constructible<number_float_t, T>::value and std::is_floating_point<T>::value>::type>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( const T  value)
inlinenoexcept

Definition at line 522 of file json.hpp.

524  {}
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:200
number value (floating-point)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( list_init_t  l,
bool  type_deduction = true,
value_t  manual_type = value_t::array 
)
inline

Definition at line 527 of file json.hpp.

528  {
529  // the initializer list could describe an object
530  bool is_object = true;
531 
532  // check if each element is an array with two elements whose first element
533  // is a string
534  for (const auto& element : l)
535  {
536  if ((element.m_final and element.m_type == value_t::array)
537  or (element.m_type != value_t::array or element.size() != 2
538  or element[0].m_type != value_t::string))
539  {
540  // we found an element that makes it impossible to use the
541  // initializer list as object
542  is_object = false;
543  break;
544  }
545  }
546 
547  // adjust type if type deduction is not wanted
548  if (not type_deduction)
549  {
550  // mark this object's type as final
551  m_final = true;
552 
553  // if array is wanted, do not create an object though possible
554  if (manual_type == value_t::array)
555  {
556  is_object = false;
557  }
558 
559  // if object is wanted but impossible, throw an exception
560  if (manual_type == value_t::object and not is_object)
561  {
562  throw std::logic_error("cannot create JSON object from initializer list");
563  }
564  }
565 
566  if (is_object)
567  {
568  // the initializer list is a list of pairs -> create object
570  Allocator<object_t> alloc;
571  m_value.object = alloc.allocate(1);
572  alloc.construct(m_value.object);
573 
574  for (auto& element : l)
575  {
576  m_value.object->emplace(std::move(*(element[0].m_value.string)), std::move(element[1]));
577  }
578  }
579  else
580  {
581  // the initializer list describes an array -> create array
583  Allocator<array_t> alloc;
584  m_value.array = alloc.allocate(1);
585  alloc.construct(m_value.array, std::move(l));
586  }
587  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
bool m_final
whether the type of JSON object may change later
Definition: json.hpp:2200
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
json_value m_value
the value of the current element
Definition: json.hpp:2203
bool is_object() const noexcept
Definition: json.hpp:793
array (ordered collection of values)
object (unordered set of name/value pairs)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &&  other)
inlinenoexcept

Definition at line 668 of file json.hpp.

669  : m_type(std::move(other.m_type)),
670  m_value(std::move(other.m_value))
671  {
672  // invalidate payload
673  other.m_type = value_t::null;
674  other.m_value = {};
675  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T >
static bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::approx ( const T  a,
const T  b 
)
inlinestaticprivate

Definition at line 2185 of file json.hpp.

2186  {
2187  return not (a > b or a < b);
2188  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::array ( list_init_t  l = list_init_t())
inlinestatic

Definition at line 590 of file json.hpp.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[]().

591  {
592  return basic_json(l, false, value_t::array);
593  }
array (ordered collection of values)
basic_json() noexcept=default
create a null object (implicitly)

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::at ( size_type  pos)
inline

Definition at line 1037 of file json.hpp.

1038  {
1039  // at only works for arrays
1040  if (m_type != value_t::array)
1041  {
1042  throw std::runtime_error("cannot use at with " + type_name());
1043  }
1044 
1045  return m_value.array->at(pos);
1046  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::at ( size_type  pos) const
inline

Definition at line 1049 of file json.hpp.

1050  {
1051  // at only works for arrays
1052  if (m_type != value_t::array)
1053  {
1054  throw std::runtime_error("cannot use at with " + type_name());
1055  }
1056 
1057  return m_value.array->at(pos);
1058  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::at ( const typename object_t::key_type &  key)
inline

Definition at line 1099 of file json.hpp.

1100  {
1101  // at only works for objects
1102  if (m_type != value_t::object)
1103  {
1104  throw std::runtime_error("cannot use at with " + type_name());
1105  }
1106 
1107  return m_value.object->at(key);
1108  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::at ( const typename object_t::key_type &  key) const
inline

Definition at line 1111 of file json.hpp.

1112  {
1113  // at only works for objects
1114  if (m_type != value_t::object)
1115  {
1116  throw std::runtime_error("cannot use at with " + type_name());
1117  }
1118 
1119  return m_value.object->at(key);
1120  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::clear ( )
inlinenoexcept

Definition at line 1481 of file json.hpp.

1482  {
1483  switch (m_type)
1484  {
1485  case (value_t::null):
1486  {
1487  break;
1488  }
1489 
1490  case (value_t::number_integer):
1491  {
1492  m_value.number_integer = 0;
1493  break;
1494  }
1495 
1496  case (value_t::number_float):
1497  {
1498  m_value.number_float = 0.0;
1499  break;
1500  }
1501 
1502  case (value_t::boolean):
1503  {
1504  m_value.boolean = false;
1505  break;
1506  }
1507 
1508  case (value_t::string):
1509  {
1510  m_value.string->clear();
1511  break;
1512  }
1513 
1514  case (value_t::array):
1515  {
1516  m_value.array->clear();
1517  break;
1518  }
1519 
1520  case (value_t::object):
1521  {
1522  m_value.object->clear();
1523  break;
1524  }
1525  }
1526  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
boolean_t boolean
bolean
Definition: json.hpp:219
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
number_integer_t number_integer
number (integer)
Definition: json.hpp:221
number_float_t number_float
number (floating-point)
Definition: json.hpp:223
object (unordered set of name/value pairs)
number value (floating-point)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::count ( typename object_t::key_type  key) const
inline

Definition at line 1246 of file json.hpp.

1247  {
1248  // return 0 for all nonobject types
1249  return (m_type == value_t::object) ? m_value.object->count(key) : 0;
1250  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::dump ( const int  indent = -1) const
inlinenoexcept

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

Parameters
indentsif 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
See also
https://docs.python.org/2/library/json.html#json.dump

Definition at line 756 of file json.hpp.

Referenced by std::hash< nlohmann::json >::operator()().

757  {
758  if (indent >= 0)
759  {
760  return dump(true, static_cast<unsigned int>(indent));
761  }
762  else
763  {
764  return dump(false, 0);
765  }
766  }
string_t dump(const int indent=-1) const noexcept
serialization
Definition: json.hpp:756

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::dump ( const bool  prettyPrint,
const unsigned int  indentStep,
const unsigned int  currentIndent = 0 
) const
inlineprivatenoexcept

This function is called by the public member function dump and organizes the serializaion 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 to a string before output using std::to_string()
  • floating-point numbers are converted to a string using "%g" format
Parameters
prettyPrintwhether the output shall be pretty-printed
indentStepthe indent level
currentIndentthe current indent level (only used internally)

Definition at line 2066 of file json.hpp.

2068  {
2069  // variable to hold indentation for recursive calls
2070  auto new_indent = currentIndent;
2071 
2072  // helper function to return whitespace as indentation
2073  const auto indent = [prettyPrint, &new_indent]()
2074  {
2075  return prettyPrint ? string_t(new_indent, ' ') : string_t();
2076  };
2077 
2078  switch (m_type)
2079  {
2080  case (value_t::object):
2081  {
2082  if (m_value.object->empty())
2083  {
2084  return "{}";
2085  }
2086 
2087  string_t result = "{";
2088 
2089  // increase indentation
2090  if (prettyPrint)
2091  {
2092  new_indent += indentStep;
2093  result += "\n";
2094  }
2095 
2096  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
2097  {
2098  if (i != m_value.object->cbegin())
2099  {
2100  result += prettyPrint ? ",\n" : ",";
2101  }
2102  result += indent() + "\"" + escape_string(i->first) + "\":" + (prettyPrint ? " " : "")
2103  + i->second.dump(prettyPrint, indentStep, new_indent);
2104  }
2105 
2106  // decrease indentation
2107  if (prettyPrint)
2108  {
2109  new_indent -= indentStep;
2110  result += "\n";
2111  }
2112 
2113  return result + indent() + "}";
2114  }
2115 
2116  case (value_t::array):
2117  {
2118  if (m_value.array->empty())
2119  {
2120  return "[]";
2121  }
2122 
2123  string_t result = "[";
2124 
2125  // increase indentation
2126  if (prettyPrint)
2127  {
2128  new_indent += indentStep;
2129  result += "\n";
2130  }
2131 
2132  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
2133  {
2134  if (i != m_value.array->cbegin())
2135  {
2136  result += prettyPrint ? ",\n" : ",";
2137  }
2138  result += indent() + i->dump(prettyPrint, indentStep, new_indent);
2139  }
2140 
2141  // decrease indentation
2142  if (prettyPrint)
2143  {
2144  new_indent -= indentStep;
2145  result += "\n";
2146  }
2147 
2148  return result + indent() + "]";
2149  }
2150 
2151  case (value_t::string):
2152  {
2153  return string_t("\"") + escape_string(*m_value.string) + "\"";
2154  }
2155 
2156  case (value_t::boolean):
2157  {
2158  return m_value.boolean ? "true" : "false";
2159  }
2160 
2161  case (value_t::number_integer):
2162  {
2163  return std::to_string(m_value.number_integer);
2164  }
2165 
2166  case (value_t::number_float):
2167  {
2168  // 15 digits of precision allows round-trip IEEE 754
2169  // string->double->string
2170  const auto sz = static_cast<unsigned int>(std::snprintf(nullptr, 0, "%.15g", m_value.number_float));
2171  std::vector<char> buf(sz + 1);
2172  std::snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
2173  return string_t(buf.data());
2174  }
2175 
2176  default:
2177  {
2178  return "null";
2179  }
2180  }
2181  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
static string_t escape_string(const string_t &s) noexcept
escape a string
Definition: json.hpp:1966
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
boolean_t boolean
bolean
Definition: json.hpp:219
json_value m_value
the value of the current element
Definition: json.hpp:2203
StringType string_t
a type for a string
Definition: json.hpp:194
array (ordered collection of values)
number_integer_t number_integer
number (integer)
Definition: json.hpp:221
number_float_t number_float
number (floating-point)
Definition: json.hpp:223
object (unordered set of name/value pairs)
number value (floating-point)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::erase ( const typename object_t::key_type &  key)
inline

Definition at line 1191 of file json.hpp.

1192  {
1193  // this erase only works for objects
1194  if (m_type != value_t::object)
1195  {
1196  throw std::runtime_error("cannot use erase with " + type_name());
1197  }
1198 
1199  return m_value.object->erase(key);
1200  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::erase ( const size_type  pos)
inline

Definition at line 1203 of file json.hpp.

1204  {
1205  // this erase only works for arrays
1206  if (m_type != value_t::array)
1207  {
1208  throw std::runtime_error("cannot use erase with " + type_name());
1209  }
1210 
1211  if (pos >= size())
1212  {
1213  throw std::out_of_range("index out of range");
1214  }
1215 
1216  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(pos));
1217  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:1417
json_value m_value
the value of the current element
Definition: json.hpp:2203
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.hpp:137
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
static string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::escape_string ( const string_t s)
inlinestaticprivatenoexcept

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
sthe string to escape
Returns
escaped string

Definition at line 1966 of file json.hpp.

1967  {
1968  // create a result string of at least the size than s
1969  string_t result;
1970  result.reserve(s.size());
1971 
1972  for (const auto c : s)
1973  {
1974  switch (c)
1975  {
1976  // quotation mark (0x22)
1977  case '"':
1978  {
1979  result += "\\\"";
1980  break;
1981  }
1982 
1983  // reverse solidus (0x5c)
1984  case '\\':
1985  {
1986  result += "\\\\";
1987  break;
1988  }
1989 
1990  // backspace (0x08)
1991  case '\b':
1992  {
1993  result += "\\b";
1994  break;
1995  }
1996 
1997  // formfeed (0x0c)
1998  case '\f':
1999  {
2000  result += "\\f";
2001  break;
2002  }
2003 
2004  // newline (0x0a)
2005  case '\n':
2006  {
2007  result += "\\n";
2008  break;
2009  }
2010 
2011  // carriage return (0x0d)
2012  case '\r':
2013  {
2014  result += "\\r";
2015  break;
2016  }
2017 
2018  // horizontal tab (0x09)
2019  case '\t':
2020  {
2021  result += "\\t";
2022  break;
2023  }
2024 
2025  default:
2026  {
2027  if (c >= 0 and c <= 0x1f)
2028  {
2029  // control characters (everything between 0x00 and 0x1f)
2030  // -> create four-digit hex representation
2031  std::stringstream ss;
2032  ss << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(c);
2033  result += ss.str();
2034  }
2035  else
2036  {
2037  // all other characters are added as-is
2038  result.append(1, c);
2039  }
2040  break;
2041  }
2042  }
2043  }
2044 
2045  return result;
2046  }
StringType string_t
a type for a string
Definition: json.hpp:194
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::find ( typename object_t::key_type  key)
inline

Definition at line 1220 of file json.hpp.

1221  {
1222  auto result = end();
1223 
1224  if (m_type == value_t::object)
1225  {
1226  result.m_it.object_iterator = m_value.object->find(key);
1227  }
1228 
1229  return result;
1230  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:1294
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
const_iterator nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::find ( typename object_t::key_type  key) const
inline

Definition at line 1233 of file json.hpp.

1234  {
1235  auto result = cend();
1236 
1237  if (m_type == value_t::object)
1238  {
1239  result.m_it.object_iterator = m_value.object->find(key);
1240  }
1241 
1242  return result;
1243  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
const_iterator cend() const noexcept
returns a const iterator to one past the last element
Definition: json.hpp:1316
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T >
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get ( ) const
inline

Definition at line 1019 of file json.hpp.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl().

1020  {
1021  return get_impl(static_cast<T*>(nullptr));
1022  }
T get_impl(T *) const
get an object (explicit)
Definition: json.hpp:827

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
allocator_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_allocator ( ) const
inline

Definition at line 179 of file json.hpp.

180  {
181  return allocator_type();
182  }
Allocator< basic_json > allocator_type
the allocator type
Definition: json.hpp:146
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = 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, typename T::mapped_type >::value, int >::type = 0>
T nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl ( T *  ) const
inlineprivate

Definition at line 827 of file json.hpp.

828  {
829  switch (m_type)
830  {
831  case (value_t::object):
832  {
833  return T(m_value.object->begin(), m_value.object->end());
834  }
835  default:
836  {
837  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(T).name());
838  }
839  }
840  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
object_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl ( object_t ) const
inlineprivate

Definition at line 843 of file json.hpp.

844  {
845  switch (m_type)
846  {
847  case (value_t::object):
848  {
849  return *(m_value.object);
850  }
851  default:
852  {
853  throw std::logic_error("cannot cast " + type_name() + " to object");
854  }
855  }
856  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<class T , typename std::enable_if< std::is_convertible< basic_json, typename T::value_type >::value andnot std::is_same< basic_json, 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, NumberFloatType, Allocator >::get_impl ( T *  ) const
inlineprivate

Definition at line 867 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get().

868  {
869  switch (m_type)
870  {
871  case (value_t::array):
872  {
873  T to_vector;
874  //to_vector.reserve(m_value.array->size());
875  std::transform(m_value.array->begin(), m_value.array->end(),
876  std::inserter(to_vector, to_vector.end()), [](basic_json i)
877  {
878  return i.get<typename T::value_type>();
879  });
880  return to_vector;
881 
882  // return T(m_value.array->begin(), m_value.array->end());
883  }
884  default:
885  {
886  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(T).name());
887  }
888  }
889  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
basic_json() noexcept=default
create a null object (implicitly)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<class T , typename std::enable_if< std::is_convertible< basic_json, T >::value andnot std::is_same< basic_json, T >::value, int >::type = 0>
std::vector<T> nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl ( std::vector< T > *  ) const
inlineprivate

Definition at line 897 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get().

898  {
899  switch (m_type)
900  {
901  case (value_t::array):
902  {
903  std::vector<T> to_vector;
904  to_vector.reserve(m_value.array->size());
905  std::transform(m_value.array->begin(), m_value.array->end(),
906  std::inserter(to_vector, to_vector.end()), [](basic_json i)
907  {
908  return i.get<T>();
909  });
910  return to_vector;
911  }
912  default:
913  {
914  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(T).name());
915  }
916  }
917  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
basic_json() noexcept=default
create a null object (implicitly)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = 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, NumberFloatType, Allocator >::get_impl ( T *  ) const
inlineprivate

Definition at line 925 of file json.hpp.

926  {
927  switch (m_type)
928  {
929  case (value_t::array):
930  {
931  return T(m_value.array->begin(), m_value.array->end());
932  }
933  default:
934  {
935  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(T).name());
936  }
937  }
938  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
array_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl ( array_t ) const
inlineprivate

Definition at line 940 of file json.hpp.

941  {
942  switch (m_type)
943  {
944  case (value_t::array):
945  {
946  return *(m_value.array);
947  }
948  default:
949  {
950  throw std::logic_error("cannot cast " + type_name() + " to array");
951  }
952  }
953  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = 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, NumberFloatType, Allocator >::get_impl ( T *  ) const
inlineprivate

Definition at line 960 of file json.hpp.

961  {
962  switch (m_type)
963  {
964  case (value_t::string):
965  {
966  return *m_value.string;
967  }
968  default:
969  {
970  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(T).name());
971  }
972  }
973  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
json_value m_value
the value of the current element
Definition: json.hpp:2203
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = 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, NumberFloatType, Allocator >::get_impl ( T *  ) const
inlineprivate

Definition at line 980 of file json.hpp.

981  {
982  switch (m_type)
983  {
985  {
986  return static_cast<T>(m_value.number_integer);
987  }
988  case (value_t::number_float):
989  {
990  return static_cast<T>(m_value.number_float);
991  }
992  default:
993  {
994  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(T).name());
995  }
996  }
997  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
number_integer_t number_integer
number (integer)
Definition: json.hpp:221
number_float_t number_float
number (floating-point)
Definition: json.hpp:223
number value (floating-point)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
boolean_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl ( boolean_t ) const
inlineprivate

Definition at line 1000 of file json.hpp.

1001  {
1002  switch (m_type)
1003  {
1004  case (value_t::boolean):
1005  {
1006  return m_value.boolean;
1007  }
1008  default:
1009  {
1010  throw std::logic_error("cannot cast " + type_name() + " to " + typeid(boolean_t).name());
1011  }
1012  }
1013  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:196
boolean_t boolean
bolean
Definition: json.hpp:219
json_value m_value
the value of the current element
Definition: json.hpp:2203
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::is_array ( ) const
inlinenoexcept

Definition at line 799 of file json.hpp.

800  {
801  return m_type == value_t::array;
802  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
array (ordered collection of values)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::is_boolean ( ) const
inlinenoexcept

Definition at line 781 of file json.hpp.

782  {
783  return m_type == value_t::boolean;
784  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::is_null ( ) const
inlinenoexcept

Definition at line 775 of file json.hpp.

776  {
777  return m_type == value_t::null;
778  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::is_number ( ) const
inlinenoexcept

Definition at line 787 of file json.hpp.

788  {
790  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
number value (floating-point)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::is_object ( ) const
inlinenoexcept

Definition at line 793 of file json.hpp.

794  {
795  return m_type == value_t::object;
796  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object (unordered set of name/value pairs)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::is_string ( ) const
inlinenoexcept

Definition at line 805 of file json.hpp.

806  {
807  return m_type == value_t::string;
808  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::object ( list_init_t  l = list_init_t())
inlinestatic

Definition at line 596 of file json.hpp.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[]().

597  {
598  return basic_json(l, false, value_t::object);
599  }
object (unordered set of name/value pairs)
basic_json() noexcept=default
create a null object (implicitly)

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T >
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator T ( ) const
inline

Definition at line 1026 of file json.hpp.

1027  {
1028  return get<T>();
1029  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator value_t ( ) const
inlinenoexcept

Definition at line 811 of file json.hpp.

812  {
813  return m_type;
814  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator+= ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &&  value)
inline

Definition at line 1553 of file json.hpp.

References nlohmann::has_mapped_type< T >::value.

1554  {
1555  push_back(std::move(value));
1556  return *this;
1557  }
void push_back(basic_json &&value)
add an object to an array
Definition: json.hpp:1529
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator+= ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &  value)
inline

Definition at line 1582 of file json.hpp.

1583  {
1584  push_back(value);
1585  return *this;
1586  }
void push_back(basic_json &&value)
add an object to an array
Definition: json.hpp:1529
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator+= ( const typename object_t::value_type &  value)
inline

Definition at line 1611 of file json.hpp.

1612  {
1613  push_back(value);
1614  return operator[](value.first);
1615  }
reference operator[](size_type pos)
access specified element
Definition: json.hpp:1061
void push_back(basic_json &&value)
add an object to an array
Definition: json.hpp:1529
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[] ( size_type  pos)
inline

Definition at line 1061 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::array().

1062  {
1063  // implicitly convert null to object
1064  if (m_type == value_t::null)
1065  {
1067  Allocator<array_t> alloc;
1068  m_value.array = alloc.allocate(1);
1069  alloc.construct(m_value.array);
1070  }
1071 
1072  // [] only works for arrays
1073  if (m_type != value_t::array)
1074  {
1075  throw std::runtime_error("cannot use [] with " + type_name());
1076  }
1077 
1078  for (size_t i = m_value.array->size(); i <= pos; ++i)
1079  {
1080  m_value.array->push_back(basic_json());
1081  }
1082 
1083  return m_value.array->operator[](pos);
1084  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
basic_json() noexcept=default
create a null object (implicitly)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[] ( size_type  pos) const
inline

Definition at line 1087 of file json.hpp.

1088  {
1089  // at only works for arrays
1090  if (m_type != value_t::array)
1091  {
1092  throw std::runtime_error("cannot use [] with " + type_name());
1093  }
1094 
1095  return m_value.array->operator[](pos);
1096  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[] ( const typename object_t::key_type &  key)
inline

Definition at line 1123 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::object().

1124  {
1125  // implicitly convert null to object
1126  if (m_type == value_t::null)
1127  {
1129  Allocator<object_t> alloc;
1130  m_value.object = alloc.allocate(1);
1131  alloc.construct(m_value.object);
1132  }
1133 
1134  // [] only works for objects
1135  if (m_type != value_t::object)
1136  {
1137  throw std::runtime_error("cannot use [] with " + type_name());
1138  }
1139 
1140  return m_value.object->operator[](key);
1141  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[] ( const typename object_t::key_type &  key) const
inline

Definition at line 1144 of file json.hpp.

1145  {
1146  // at only works for objects
1147  if (m_type != value_t::object)
1148  {
1149  throw std::runtime_error("cannot use [] with " + type_name());
1150  }
1151 
1152  return m_value.object->operator[](key);
1153  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T , size_t n>
reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[] ( const T(&)  key[n])
inline

Definition at line 1157 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::object().

1158  {
1159  // implicitly convert null to object
1160  if (m_type == value_t::null)
1161  {
1163  Allocator<object_t> alloc;
1164  m_value.object = alloc.allocate(1);
1165  alloc.construct(m_value.object);
1166  }
1167 
1168  // at only works for objects
1169  if (m_type != value_t::object)
1170  {
1171  throw std::runtime_error("cannot use [] with " + type_name());
1172  }
1173 
1174  return m_value.object->operator[](key);
1175  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
template<typename T , size_t n>
const_reference nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[] ( const T(&)  key[n]) const
inline

Definition at line 1179 of file json.hpp.

1180  {
1181  // at only works for objects
1182  if (m_type != value_t::object)
1183  {
1184  throw std::runtime_error("cannot use [] with " + type_name());
1185  }
1186 
1187  return m_value.object->operator[](key);
1188  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::parse ( const string_t s)
inlinestatic

Definition at line 1887 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::parser::parse().

Referenced by operator""_json().

1888  {
1889  return parser(s).parse();
1890  }

Here is the call graph for this function:

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
static basic_json nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::parse ( std::istream &  i)
inlinestatic

Definition at line 1893 of file json.hpp.

References nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::parser::parse().

1894  {
1895  return parser(i).parse();
1896  }

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::push_back ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &&  value)
inline

Definition at line 1529 of file json.hpp.

References nlohmann::has_mapped_type< T >::value.

Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::parser::parse_internal().

1530  {
1531  // push_back only works for null objects or arrays
1532  if (not(m_type == value_t::null or m_type == value_t::array))
1533  {
1534  throw std::runtime_error("cannot add element to " + type_name());
1535  }
1536 
1537  // transform null object into an array
1538  if (m_type == value_t::null)
1539  {
1541  Allocator<array_t> alloc;
1542  m_value.array = alloc.allocate(1);
1543  alloc.construct(m_value.array);
1544  }
1545 
1546  // add element to array (move semantics)
1547  m_value.array->push_back(std::move(value));
1548  // invalidate object
1549  value.m_type = value_t::null;
1550  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::push_back ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &  value)
inline

Definition at line 1560 of file json.hpp.

1561  {
1562  // push_back only works for null objects or arrays
1563  if (not(m_type == value_t::null or m_type == value_t::array))
1564  {
1565  throw std::runtime_error("cannot add element to " + type_name());
1566  }
1567 
1568  // transform null object into an array
1569  if (m_type == value_t::null)
1570  {
1572  Allocator<array_t> alloc;
1573  m_value.array = alloc.allocate(1);
1574  alloc.construct(m_value.array);
1575  }
1576 
1577  // add element to array
1578  m_value.array->push_back(value);
1579  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::push_back ( const typename object_t::value_type &  value)
inline

Definition at line 1589 of file json.hpp.

1590  {
1591  // push_back only works for null objects or objects
1592  if (not(m_type == value_t::null or m_type == value_t::object))
1593  {
1594  throw std::runtime_error("cannot add element to " + type_name());
1595  }
1596 
1597  // transform null object into an object
1598  if (m_type == value_t::null)
1599  {
1601  Allocator<object_t> alloc;
1602  m_value.object = alloc.allocate(1);
1603  alloc.construct(m_value.object);
1604  }
1605 
1606  // add element to array
1607  m_value.object->insert(value);
1608  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::swap ( array_t other)
inline

Definition at line 1633 of file json.hpp.

References std::swap().

1634  {
1635  // swap only works for arrays
1636  if (m_type != value_t::array)
1637  {
1638  throw std::runtime_error("cannot use swap with " + type_name());
1639  }
1640 
1641  // swap arrays
1642  std::swap(*(m_value.array), other);
1643  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
json_value m_value
the value of the current element
Definition: json.hpp:2203
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value andis_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
Definition: json.hpp:4695
array (ordered collection of values)
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:215
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::swap ( object_t other)
inline

Definition at line 1646 of file json.hpp.

References std::swap().

1647  {
1648  // swap only works for objects
1649  if (m_type != value_t::object)
1650  {
1651  throw std::runtime_error("cannot use swap with " + type_name());
1652  }
1653 
1654  // swap arrays
1655  std::swap(*(m_value.object), other);
1656  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:213
json_value m_value
the value of the current element
Definition: json.hpp:2203
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value andis_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
Definition: json.hpp:4695
object (unordered set of name/value pairs)
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::swap ( string_t other)
inline

Definition at line 1659 of file json.hpp.

References std::swap().

1660  {
1661  // swap only works for strings
1662  if (m_type != value_t::string)
1663  {
1664  throw std::runtime_error("cannot use swap with " + type_name());
1665  }
1666 
1667  // swap arrays
1668  std::swap(*(m_value.string), other);
1669  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:217
json_value m_value
the value of the current element
Definition: json.hpp:2203
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value andis_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
Definition: json.hpp:4695
string_t type_name() const noexcept
return the type as string
Definition: json.hpp:1919

Here is the call 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::type ( ) const
inlinenoexcept

Definition at line 769 of file json.hpp.

770  {
771  return m_type;
772  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::type_name ( ) const
inlineprivatenoexcept

Definition at line 1919 of file json.hpp.

1920  {
1921  switch (m_type)
1922  {
1923  case (value_t::null):
1924  {
1925  return "null";
1926  }
1927 
1928  case (value_t::object):
1929  {
1930  return "object";
1931  }
1932 
1933  case (value_t::array):
1934  {
1935  return "array";
1936  }
1937 
1938  case (value_t::string):
1939  {
1940  return "string";
1941  }
1942 
1943  case (value_t::boolean):
1944  {
1945  return "boolean";
1946  }
1947 
1948  default:
1949  {
1950  return "number";
1951  }
1952  }
1953  }
value_t m_type
the type of the current element
Definition: json.hpp:2197
array (ordered collection of values)
object (unordered set of name/value pairs)

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool operator< ( const value_t  lhs,
const value_t  rhs 
)
friend

Returns an ordering that is similar to Python:

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

Definition at line 259 of file json.hpp.

260  {
261  // no type is smaller than itself
262  if (lhs == rhs)
263  {
264  return false;
265  }
266 
267  switch (lhs)
268  {
269  case (value_t::null):
270  {
271  // nulls are smaller than all other types
272  return true;
273  }
274 
275  case (value_t::boolean):
276  {
277  // only nulls are smaller than booleans
278  return (rhs != value_t::null);
279  }
280 
281  case (value_t::number_float):
283  {
284  switch (rhs)
285  {
286  // numbers are smaller than objects, arrays, and string
287  case (value_t::object):
288  case (value_t::array):
289  case (value_t::string):
290  {
291  return true;
292  }
293 
294  default:
295  {
296  return false;
297  }
298  }
299  }
300 
301  case (value_t::object):
302  {
303  switch (rhs)
304  {
305  // objects are smaller than arrays and string
306  case (value_t::array):
307  case (value_t::string):
308  {
309  return true;
310  }
311 
312  default:
313  {
314  return false;
315  }
316  }
317  }
318 
319  case (value_t::array):
320  {
321  // arrays are smaller than strings
322  return (rhs == value_t::string);
323  }
324 
325  default:
326  {
327  // a string is not smaller than any other types
328  return false;
329  }
330  }
331  }
array (ordered collection of values)
object (unordered set of name/value pairs)
number value (floating-point)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool operator< ( const_reference  lhs,
const_reference  rhs 
)
friend

Definition at line 1763 of file json.hpp.

1764  {
1765  switch (lhs.type())
1766  {
1767  case (value_t::array):
1768  {
1769  if (rhs.type() == value_t::array)
1770  {
1771  return *lhs.m_value.array < *rhs.m_value.array;
1772  }
1773  break;
1774  }
1775  case (value_t::object):
1776  {
1777  if (rhs.type() == value_t::object)
1778  {
1779  return *lhs.m_value.object < *rhs.m_value.object;
1780  }
1781  break;
1782  }
1783  case (value_t::null):
1784  {
1785  if (rhs.type() == value_t::null)
1786  {
1787  return false;
1788  }
1789  break;
1790  }
1791  case (value_t::string):
1792  {
1793  if (rhs.type() == value_t::string)
1794  {
1795  return *lhs.m_value.string < *rhs.m_value.string;
1796  }
1797  break;
1798  }
1799  case (value_t::boolean):
1800  {
1801  if (rhs.type() == value_t::boolean)
1802  {
1803  return lhs.m_value.boolean < rhs.m_value.boolean;
1804  }
1805  break;
1806  }
1807  case (value_t::number_integer):
1808  {
1809  if (rhs.type() == value_t::number_integer)
1810  {
1811  return lhs.m_value.number_integer < rhs.m_value.number_integer;
1812  }
1813  if (rhs.type() == value_t::number_float)
1814  {
1815  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_float);
1816  }
1817  break;
1818  }
1819  case (value_t::number_float):
1820  {
1821  if (rhs.type() == value_t::number_integer)
1822  {
1823  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
1824  }
1825  if (rhs.type() == value_t::number_float)
1826  {
1827  return lhs.m_value.number_float < rhs.m_value.number_float;
1828  }
1829  break;
1830  }
1831  }
1832 
1833  // We only reach this line if we cannot compare values. In that case,
1834  // we compare types.
1835  return lhs.type() < rhs.type();
1836  }
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:198
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:200
array (ordered collection of values)
object (unordered set of name/value pairs)
number value (floating-point)
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
std::ostream& operator<< ( std::ostream &  o,
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &  j 
)
friend

Definition at line 1862 of file json.hpp.

1863  {
1864  // read width member and use it as indentation parameter if nonzero
1865  const int indentation = (o.width() == 0) ? -1 : o.width();
1866 
1867  o << j.dump(indentation);
1868  return o;
1869  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
std::istream& operator<< ( basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &  j,
std::istream &  i 
)
friend

Definition at line 1906 of file json.hpp.

1907  {
1908  j = parser(i).parse();
1909  return i;
1910  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool operator<= ( const_reference  lhs,
const_reference  rhs 
)
friend

Definition at line 1839 of file json.hpp.

1840  {
1841  return not (rhs < lhs);
1842  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool operator> ( const_reference  lhs,
const_reference  rhs 
)
friend

Definition at line 1845 of file json.hpp.

1846  {
1847  return not (lhs <= rhs);
1848  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool operator>= ( const_reference  lhs,
const_reference  rhs 
)
friend

Definition at line 1851 of file json.hpp.

1852  {
1853  return not (lhs < rhs);
1854  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
std::ostream& operator>> ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &  j,
std::ostream &  o 
)
friend

Definition at line 1872 of file json.hpp.

1873  {
1874  // read width member and use it as indentation parameter if nonzero
1875  const int indentation = (o.width() == 0) ? -1 : o.width();
1876 
1877  o << j.dump(indentation);
1878  return o;
1879  }
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
std::istream& operator>> ( std::istream &  i,
basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator > &  j 
)
friend

Definition at line 1899 of file json.hpp.

1900  {
1901  j = parser(i).parse();
1902  return i;
1903  }

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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
bool nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::m_final = false
private

Definition at line 2200 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
value_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::m_type = value_t::null
private

Definition at line 2197 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 = int64_t, class NumberFloatType = double, template< typename U > class Allocator = std::allocator>
json_value nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::m_value = {}
private

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