All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value Union Reference

a JSON value More...

Public Member Functions

 json_value ()=default
 default constructor (for null values) More...
 
 json_value (boolean_t v) noexcept
 constructor for booleans More...
 
 json_value (number_integer_t v) noexcept
 constructor for numbers (integer) More...
 
 json_value (number_unsigned_t v) noexcept
 constructor for numbers (unsigned) More...
 
 json_value (number_float_t v) noexcept
 constructor for numbers (floating-point) More...
 
 json_value (value_t t)
 constructor for empty values of a given type More...
 
 json_value (const string_t &value)
 constructor for strings More...
 
 json_value (string_t &&value)
 constructor for rvalue strings More...
 
 json_value (const object_t &value)
 constructor for objects More...
 
 json_value (object_t &&value)
 constructor for rvalue objects More...
 
 json_value (const array_t &value)
 constructor for arrays More...
 
 json_value (array_t &&value)
 constructor for rvalue arrays More...
 
void destroy (value_t t) noexcept
 

Public Attributes

object_tobject
 object (stored with pointer to save storage) More...
 
array_tarray
 array (stored with pointer to save storage) More...
 
string_tstring
 string (stored with pointer to save storage) More...
 
boolean_t boolean
 boolean More...
 
number_integer_t number_integer
 number (integer) More...
 
number_unsigned_t number_unsigned
 number (unsigned integer) More...
 
number_float_t number_float
 number (floating-point) More...
 

Detailed Description

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

a JSON value

The actual storage for a JSON value of the basic_json class. This union combines the different storage types for the JSON value types defined in value_t.

JSON type value_t type used type
object object pointer to object_t
array array pointer to array_t
string string pointer to string_t
boolean boolean boolean_t
number number_integer number_integer_t
number number_unsigned number_unsigned_t
number number_float number_float_t
null null no value is stored
Note
Variable-length types (objects, arrays, and strings) are stored as pointers. The size of the union should not exceed 64 bits if the default value types are used.
Since
version 1.0.0

Definition at line 15414 of file json.hpp.

Constructor & Destructor Documentation

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

default constructor (for null 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 = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( boolean_t  v)
inlinenoexcept

constructor for booleans

Definition at line 15434 of file json.hpp.

15434 : boolean(v) {}
boolean_t boolean
boolean
Definition: json.hpp:15423
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( number_integer_t  v)
inlinenoexcept

constructor for numbers (integer)

Definition at line 15436 of file json.hpp.

15436 : number_integer(v) {}
number_integer_t number_integer
number (integer)
Definition: json.hpp:15425
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( number_unsigned_t  v)
inlinenoexcept

constructor for numbers (unsigned)

Definition at line 15438 of file json.hpp.

15438 : number_unsigned(v) {}
number_unsigned_t number_unsigned
number (unsigned integer)
Definition: json.hpp:15427
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( number_float_t  v)
inlinenoexcept

constructor for numbers (floating-point)

Definition at line 15440 of file json.hpp.

15440 : number_float(v) {}
number_float_t number_float
number (floating-point)
Definition: json.hpp:15429
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( value_t  t)
inline

constructor for empty values of a given type

Definition at line 15442 of file json.hpp.

15443  {
15444  switch (t)
15445  {
15446  case value_t::object:
15447  {
15448  object = create<object_t>();
15449  break;
15450  }
15451 
15452  case value_t::array:
15453  {
15454  array = create<array_t>();
15455  break;
15456  }
15457 
15458  case value_t::string:
15459  {
15460  string = create<string_t>("");
15461  break;
15462  }
15463 
15464  case value_t::boolean:
15465  {
15466  boolean = boolean_t(false);
15467  break;
15468  }
15469 
15471  {
15473  break;
15474  }
15475 
15477  {
15479  break;
15480  }
15481 
15482  case value_t::number_float:
15483  {
15485  break;
15486  }
15487 
15488  case value_t::null:
15489  {
15490  object = nullptr; // silence warning, see #821
15491  break;
15492  }
15493 
15494  default:
15495  {
15496  object = nullptr; // silence warning, see #821
15498  {
15499  JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.7.3")); // LCOV_EXCL_LINE
15500  }
15501  break;
15502  }
15503  }
15504  }
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:15362
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:15419
array (ordered collection of values)
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition: json.hpp:15294
static other_error create(int id_, const std::string &what_arg)
Definition: json.hpp:2163
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:15223
number value (signed integer)
number_unsigned_t number_unsigned
number (unsigned integer)
Definition: json.hpp:15427
number_float_t number_float
number (floating-point)
Definition: json.hpp:15429
#define JSON_THROW(exception)
Definition: json.hpp:1754
object (unordered set of name/value pairs)
BooleanType boolean_t
a type for a boolean
Definition: json.hpp:15151
number_integer_t number_integer
number (integer)
Definition: json.hpp:15425
number value (unsigned integer)
number value (floating-point)
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( const string_t value)
inline

constructor for strings

Definition at line 15507 of file json.hpp.

15508  {
15509  string = create<string_t>(value);
15510  }
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:18003
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( string_t &&  value)
inline

constructor for rvalue strings

Definition at line 15513 of file json.hpp.

15514  {
15515  string = create<string_t>(std::move(value));
15516  }
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:18003
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( const object_t value)
inline

constructor for objects

Definition at line 15519 of file json.hpp.

15520  {
15521  object = create<object_t>(value);
15522  }
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:18003
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( object_t &&  value)
inline

constructor for rvalue objects

Definition at line 15525 of file json.hpp.

15526  {
15527  object = create<object_t>(std::move(value));
15528  }
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:18003
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( const array_t value)
inline

constructor for arrays

Definition at line 15531 of file json.hpp.

15532  {
15533  array = create<array_t>(value);
15534  }
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:18003
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:15419
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::json_value::json_value ( array_t &&  value)
inline

constructor for rvalue arrays

Definition at line 15537 of file json.hpp.

15538  {
15539  array = create<array_t>(std::move(value));
15540  }
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition: json.hpp:18003
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:15419

Member Function Documentation

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

Definition at line 15542 of file json.hpp.

15543  {
15544  // flatten the current json_value to a heap-allocated stack
15545  std::vector<basic_json> stack;
15546 
15547  // move the top-level items to stack
15548  if (t == value_t::array)
15549  {
15550  stack.reserve(array->size());
15551  std::move(array->begin(), array->end(), std::back_inserter(stack));
15552  }
15553  else if (t == value_t::object)
15554  {
15555  stack.reserve(object->size());
15556  for (auto&& it : *object)
15557  {
15558  stack.push_back(std::move(it.second));
15559  }
15560  }
15561 
15562  while (not stack.empty())
15563  {
15564  // move the last item to local variable to be processed
15565  basic_json current_item(std::move(stack.back()));
15566  stack.pop_back();
15567 
15568  // if current_item is array/object, move
15569  // its children to the stack to be processed later
15570  if (current_item.is_array())
15571  {
15572  std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
15573  std::back_inserter(stack));
15574 
15575  current_item.m_value.array->clear();
15576  }
15577  else if (current_item.is_object())
15578  {
15579  for (auto&& it : *current_item.m_value.object)
15580  {
15581  stack.push_back(std::move(it.second));
15582  }
15583 
15584  current_item.m_value.object->clear();
15585  }
15586 
15587  // it's now safe that current_item get destructed
15588  // since it doesn't have any children
15589  }
15590 
15591  switch (t)
15592  {
15593  case value_t::object:
15594  {
15595  AllocatorType<object_t> alloc;
15596  std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
15597  std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);
15598  break;
15599  }
15600 
15601  case value_t::array:
15602  {
15603  AllocatorType<array_t> alloc;
15604  std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
15605  std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
15606  break;
15607  }
15608 
15609  case value_t::string:
15610  {
15611  AllocatorType<string_t> alloc;
15612  std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
15613  std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
15614  break;
15615  }
15616 
15617  default:
15618  {
15619  break;
15620  }
15621  }
15622  }
object_t * object
object (stored with pointer to save storage)
Definition: json.hpp:15417
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:15419
string_t * string
string (stored with pointer to save storage)
Definition: json.hpp:15421
array (ordered collection of values)
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:15752
object (unordered set of name/value pairs)

Member Data Documentation

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

array (stored with pointer to save storage)

Definition at line 15419 of file json.hpp.

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

boolean

Definition at line 15423 of file json.hpp.

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

number (floating-point)

Definition at line 15429 of file json.hpp.

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

number (integer)

Definition at line 15425 of file json.hpp.

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

number (unsigned integer)

Definition at line 15427 of file json.hpp.

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

object (stored with pointer to save storage)

Definition at line 15417 of file json.hpp.

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

string (stored with pointer to save storage)

Definition at line 15421 of file json.hpp.


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