Crossfire Server, Trunk
|
a class to store JSON values More...
#include <json.hpp>
Public Types | |
using | cbor_tag_handler_t = detail::cbor_tag_handler_t |
how to treat CBOR tags More... | |
using | error_handler_t = detail::error_handler_t |
how to treat decoding errors More... | |
using | initializer_list_t = std::initializer_list< detail::json_ref< basic_json > > |
helper type for initializer lists of basic_json values More... | |
using | input_format_t = detail::input_format_t |
using | json_pointer = ::nlohmann::json_pointer< basic_json > |
JSON Pointer, see nlohmann::json_pointer. More... | |
using | json_sax_t = json_sax< basic_json > |
SAX interface type, see nlohmann::json_sax. More... | |
template<typename T , typename SFINAE > | |
using | json_serializer = JSONSerializer< T, SFINAE > |
using | parse_event_t = detail::parse_event_t |
parser event types More... | |
using | parser_callback_t = detail::parser_callback_t< basic_json > |
per-element parser callback type More... | |
using | value_t = detail::value_t |
Public Member Functions | |
const JSON_HEDLEY_RETURNS_NON_NULL char * | type_name () const noexcept |
return the type as string More... | |
Static Public Member Functions | |
static allocator_type | get_allocator () |
returns the allocator associated with the container More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | meta () |
returns version information on the library More... | |
Data Fields | |
JSON_PRIVATE_UNLESS_TESTED | __pad3__: value_t m_type = value_t::null |
json_value | m_value = {} |
the value of the current element More... | |
Private Types | |
using | basic_json_t = NLOHMANN_BASIC_JSON_TPL |
workaround type for MSVC More... | |
template<typename InputType > | |
using | binary_reader = ::nlohmann::detail::binary_reader< basic_json, InputType > |
template<typename CharType > | |
using | binary_writer = ::nlohmann::detail::binary_writer< basic_json, CharType > |
template<typename BasicJsonType > | |
using | internal_iterator = ::nlohmann::detail::internal_iterator< BasicJsonType > |
template<typename BasicJsonType > | |
using | iter_impl = ::nlohmann::detail::iter_impl< BasicJsonType > |
template<typename Iterator > | |
using | iteration_proxy = ::nlohmann::detail::iteration_proxy< Iterator > |
template<typename Base > | |
using | json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator< Base > |
template<typename CharType > | |
using | output_adapter_t = ::nlohmann::detail::output_adapter_t< CharType > |
using | primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t |
Private Member Functions | |
void | assert_invariant (bool check_parents=true) const noexcept |
checks the class invariants More... | |
void | destroy (value_t t) |
boolean_t | get_impl (boolean_t *) const |
get a boolean (explicit) More... | |
array_t * | get_impl_ptr (array_t *) noexcept |
get a pointer to the value (array) More... | |
binary_t * | get_impl_ptr (binary_t *) noexcept |
get a pointer to the value (binary) More... | |
boolean_t * | get_impl_ptr (boolean_t *) noexcept |
get a pointer to the value (boolean) More... | |
constexpr const array_t * | get_impl_ptr (const array_t *) const noexcept |
get a pointer to the value (array) More... | |
constexpr const binary_t * | get_impl_ptr (const binary_t *) const noexcept |
get a pointer to the value (binary) More... | |
constexpr const boolean_t * | get_impl_ptr (const boolean_t *) const noexcept |
get a pointer to the value (boolean) More... | |
constexpr const number_float_t * | get_impl_ptr (const number_float_t *) const noexcept |
get a pointer to the value (floating-point number) More... | |
constexpr const number_integer_t * | get_impl_ptr (const number_integer_t *) const noexcept |
get a pointer to the value (integer number) More... | |
constexpr const number_unsigned_t * | get_impl_ptr (const number_unsigned_t *) const noexcept |
get a pointer to the value (unsigned number) More... | |
constexpr const object_t * | get_impl_ptr (const object_t *) const noexcept |
get a pointer to the value (object) More... | |
constexpr const string_t * | get_impl_ptr (const string_t *) const noexcept |
get a pointer to the value (string) More... | |
number_float_t * | get_impl_ptr (number_float_t *) noexcept |
get a pointer to the value (floating-point number) More... | |
number_integer_t * | get_impl_ptr (number_integer_t *) noexcept |
get a pointer to the value (integer number) More... | |
number_unsigned_t * | get_impl_ptr (number_unsigned_t *) noexcept |
get a pointer to the value (unsigned number) More... | |
object_t * | get_impl_ptr (object_t *) noexcept |
get a pointer to the value (object) More... | |
string_t * | get_impl_ptr (string_t *) noexcept |
get a pointer to the value (string) More... | |
json_value ()=default | |
default constructor (for null values) More... | |
json_value (array_t &&value) | |
constructor for rvalue arrays More... | |
json_value (binary_t &&value) | |
constructor for rvalue binary arrays (internal type) More... | |
json_value (boolean_t v) noexcept | |
constructor for booleans More... | |
json_value (const array_t &value) | |
constructor for arrays More... | |
json_value (const binary_t &value) | |
constructor for binary arrays (internal type) More... | |
json_value (const object_t &value) | |
constructor for objects More... | |
json_value (const string_t &value) | |
constructor for strings More... | |
json_value (const typename binary_t::container_type &value) | |
constructor for binary arrays More... | |
json_value (number_float_t v) noexcept | |
constructor for numbers (floating-point) 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 (object_t &&value) | |
constructor for rvalue objects More... | |
json_value (string_t &&value) | |
constructor for rvalue strings More... | |
json_value (typename binary_t::container_type &&value) | |
constructor for rvalue binary arrays More... | |
json_value (value_t t) | |
constructor for empty values of a given type More... | |
template<typename InputAdapterType > | |
static ::nlohmann::detail::parser< basic_json, InputAdapterType > | parser (InputAdapterType adapter, detail::parser_callback_t< basic_json >cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false) |
reference | set_parent (reference j, std::size_t old_capacity=std::size_t(-1)) |
void | set_parents () |
iterator | set_parents (iterator it, typename iterator::difference_type count) |
Static Private Member Functions | |
template<typename T , typename... Args> | |
static JSON_HEDLEY_RETURNS_NON_NULL T * | create (Args &&... args) |
helper for exception-safe object creation More... | |
template<typename ReferenceType , typename ThisType > | |
static ReferenceType | get_ref_impl (ThisType &obj) |
helper function to implement get_ref() More... | |
Private Attributes | |
JSON_PRIVATE_UNLESS_TESTED | __pad0__: using lexer = ::nlohmann::detail::lexer_base<basic_json> |
JSON_PRIVATE_UNLESS_TESTED | __pad1__: using serializer = ::nlohmann::detail::serializer<basic_json> |
JSON_PRIVATE_UNLESS_TESTED | __pad2__: union json_value { object_t* object |
array_t * | array |
array (stored with pointer to save storage) More... | |
binary_t * | binary |
binary (stored with pointer to save storage) More... | |
boolean_t | boolean |
boolean More... | |
number_float_t | number_float |
number (floating-point) More... | |
number_integer_t | number_integer |
number (integer) More... | |
number_unsigned_t | number_unsigned |
number (unsigned integer) More... | |
string_t * | string |
string (stored with pointer to save storage) More... | |
Friends | |
template<typename BasicJsonType , typename InputType , typename SAX > | |
class | ::nlohmann::detail::binary_reader |
template<typename BasicJsonType , typename CharType > | |
class | ::nlohmann::detail::binary_writer |
class | ::nlohmann::detail::exception |
template<typename BasicJsonType > | |
class | ::nlohmann::detail::iter_impl |
template<typename BasicJsonType > | |
class | ::nlohmann::detail::json_sax_dom_callback_parser |
template<typename BasicJsonType > | |
class | ::nlohmann::detail::json_sax_dom_parser |
template<typename BasicJsonType , typename InputType > | |
class | ::nlohmann::detail::parser |
template<detail::value_t > | |
struct | detail::external_constructor |
exceptions | |
using | exception = detail::exception |
general exception of the basic_json class More... | |
using | parse_error = detail::parse_error |
exception indicating a parse error More... | |
using | invalid_iterator = detail::invalid_iterator |
exception indicating errors with iterators More... | |
using | type_error = detail::type_error |
exception indicating executing a member function with a wrong type More... | |
using | out_of_range = detail::out_of_range |
exception indicating access out of the defined range More... | |
using | other_error = detail::other_error |
exception indicating other library errors More... | |
container types | |
The canonic container types to use basic_json like any other STL container. | |
using | value_type = basic_json |
the type of elements in a basic_json container More... | |
using | reference = value_type & |
the type of an element reference More... | |
using | const_reference = const value_type & |
the type of an element const reference More... | |
using | difference_type = std::ptrdiff_t |
a type to represent differences between iterators More... | |
using | size_type = std::size_t |
a type to represent container sizes More... | |
using | allocator_type = AllocatorType< basic_json > |
the allocator type More... | |
using | pointer = typename std::allocator_traits< allocator_type >::pointer |
the type of an element pointer More... | |
using | const_pointer = typename std::allocator_traits< allocator_type >::const_pointer |
the type of an element const pointer More... | |
using | iterator = iter_impl< basic_json > |
an iterator for a basic_json container More... | |
using | const_iterator = iter_impl< const basic_json > |
a const iterator for a basic_json container More... | |
using | reverse_iterator = json_reverse_iterator< typename basic_json::iterator > |
a reverse iterator for a basic_json container More... | |
using | const_reverse_iterator = json_reverse_iterator< typename basic_json::const_iterator > |
a const reverse iterator for a basic_json container More... | |
JSON value data types | |
The data types to store a JSON value. These types are derived from the template arguments passed to class basic_json. | |
using | object_comparator_t = std::less< StringType > |
using | object_t = ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >> |
a type for an object More... | |
using | array_t = ArrayType< basic_json, AllocatorType< basic_json > > |
a type for an array More... | |
using | string_t = StringType |
a type for a string More... | |
using | boolean_t = BooleanType |
a type for a boolean More... | |
using | number_integer_t = NumberIntegerType |
a type for a number (integer) More... | |
using | number_unsigned_t = NumberUnsignedType |
a type for a number (unsigned) More... | |
using | number_float_t = NumberFloatType |
a type for a number (floating-point) More... | |
using | binary_t = nlohmann::byte_container_with_subtype< BinaryType > |
a type for a packed binary type More... | |
constructors and destructors | |
Constructors of class basic_json, copy/move constructor, copy assignment, static functions creating objects, and the destructor. | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | binary (const typename binary_t::container_type &init) |
explicitly create a binary array (without subtype) More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | binary (const typename binary_t::container_type &init, typename binary_t::subtype_type subtype) |
explicitly create a binary array (with subtype) More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | binary (typename binary_t::container_type &&init) |
explicitly create a binary array (without subtype) More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | binary (typename binary_t::container_type &&init, typename binary_t::subtype_type subtype) |
explicitly create a binary array (with subtype) More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | array (initializer_list_t init={}) |
explicitly create an array from an initializer list More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | object (initializer_list_t init={}) |
explicitly create an object from an initializer list More... | |
basic_json (const value_t v) | |
create an empty value with a given type More... | |
basic_json (std::nullptr_t=nullptr) noexcept | |
create a null object More... | |
template<typename CompatibleType , typename U = detail::uncvref_t<CompatibleType>, detail::enable_if_t< !detail::is_basic_json< U >::value &&detail::is_compatible_type< basic_json_t, U >::value, int > = 0> | |
basic_json (CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val)))) | |
create a JSON value More... | |
template<typename BasicJsonType , detail::enable_if_t< detail::is_basic_json< BasicJsonType >::value &&!std::is_same< basic_json, BasicJsonType >::value, int > = 0> | |
basic_json (const BasicJsonType &val) | |
create a JSON value from an existing one More... | |
basic_json (initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array) | |
create a container (array or object) from an initializer list More... | |
basic_json (size_type cnt, const basic_json &val) | |
construct an array with count copies of given value More... | |
template<class InputIT , typename std::enable_if< std::is_same< InputIT, typename basic_json_t::iterator >::value||std::is_same< InputIT, typename basic_json_t::const_iterator >::value, int >::type = 0> | |
basic_json (InputIT first, InputIT last) | |
construct a JSON container given an iterator range More... | |
template<typename JsonRef , detail::enable_if_t< detail::conjunction< detail::is_json_ref< JsonRef >, std::is_same< typename JsonRef::value_type, basic_json >>::value, int > = 0> | |
basic_json (const JsonRef &ref) | |
basic_json (const basic_json &other) | |
copy constructor More... | |
basic_json (basic_json &&other) noexcept | |
move constructor More... | |
basic_json & | operator= (basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value) |
copy assignment More... | |
~basic_json () noexcept | |
destructor More... | |
object inspection | |
string_t | dump (const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const |
serialization More... | |
constexpr value_t | type () const noexcept |
return the type of the JSON value (explicit) More... | |
constexpr bool | is_primitive () const noexcept |
return whether type is primitive More... | |
constexpr bool | is_structured () const noexcept |
return whether type is structured More... | |
constexpr bool | is_null () const noexcept |
return whether value is null More... | |
constexpr bool | is_boolean () const noexcept |
return whether value is a boolean More... | |
constexpr bool | is_number () const noexcept |
return whether value is a number More... | |
constexpr bool | is_number_integer () const noexcept |
return whether value is an integer number More... | |
constexpr bool | is_number_unsigned () const noexcept |
return whether value is an unsigned integer number More... | |
constexpr bool | is_number_float () const noexcept |
return whether value is a floating-point number More... | |
constexpr bool | is_object () const noexcept |
return whether value is an object More... | |
constexpr bool | is_array () const noexcept |
return whether value is an array More... | |
constexpr bool | is_string () const noexcept |
return whether value is a string More... | |
constexpr bool | is_binary () const noexcept |
return whether value is a binary array More... | |
constexpr bool | is_discarded () const noexcept |
return whether value is discarded More... | |
constexpr | operator value_t () const noexcept |
return the type of the JSON value (implicit) More... | |
value access | |
template<typename ValueType , detail::enable_if_t< detail::is_default_constructible< ValueType >::value &&detail::has_from_json< basic_json_t, ValueType >::value, int > = 0> | |
ValueType | get_impl (detail::priority_tag< 0 >) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), std::declval< ValueType & >()))) |
get a value (explicit) More... | |
template<typename ValueType , detail::enable_if_t< detail::has_non_default_from_json< basic_json_t, ValueType >::value, int > = 0> | |
ValueType | get_impl (detail::priority_tag< 1 >) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >()))) |
get a value (explicit); special case More... | |
template<typename BasicJsonType , detail::enable_if_t< detail::is_basic_json< BasicJsonType >::value, int > = 0> | |
BasicJsonType | get_impl (detail::priority_tag< 2 >) const |
get special-case overload More... | |
template<typename BasicJsonType , detail::enable_if_t< std::is_same< BasicJsonType, basic_json_t >::value, int > = 0> | |
basic_json | get_impl (detail::priority_tag< 3 >) const |
get special-case overload More... | |
template<typename PointerType , detail::enable_if_t< std::is_pointer< PointerType >::value, int > = 0> | |
constexpr auto | get_impl (detail::priority_tag< 4 >) const noexcept -> decltype(std::declval< const basic_json_t & >().template get_ptr< PointerType >()) |
get a pointer value (explicit) More... | |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0> | |
auto | get_ptr () noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >())) |
get a pointer value (implicit) More... | |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value &&std::is_const< typename std::remove_pointer< PointerType >::type >::value, int >::type = 0> | |
constexpr auto | get_ptr () const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >())) |
get a pointer value (implicit) More... | |
template<typename ValueTypeCV , typename ValueType = detail::uncvref_t<ValueTypeCV>> | |
auto | get () const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > |
get a (pointer) value (explicit) More... | |
return | get_impl (detail::priority_tag< 4 > {}) |
template<typename PointerType , typename std::enable_if< std::is_pointer< PointerType >::value, int >::type = 0> | |
auto | get () noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >()) |
get a pointer value (explicit) More... | |
template<typename ValueType , detail::enable_if_t< !detail::is_basic_json< ValueType >::value &&detail::has_from_json< basic_json_t, ValueType >::value, int > = 0> | |
ValueType & | get_to (ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v))) |
get a value (explicit) More... | |
template<typename ValueType , detail::enable_if_t< detail::is_basic_json< ValueType >::value, int > = 0> | |
ValueType & | get_to (ValueType &v) const |
template<typename T , std::size_t N, typename Array = T (&)[N], detail::enable_if_t< detail::has_from_json< basic_json_t, Array >::value, int > = 0> | |
Array | get_to (T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v))) |
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value, int >::type = 0> | |
ReferenceType | get_ref () |
get a reference value (implicit) More... | |
template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value &&std::is_const< typename std::remove_reference< ReferenceType >::type >::value, int >::type = 0> | |
ReferenceType | get_ref () const |
get a reference value (implicit) More... | |
template<typename ValueType , typename std::enable_if< detail::conjunction< detail::negation< std::is_pointer< ValueType >>, detail::negation< std::is_same< ValueType, detail::json_ref< basic_json >>>, detail::negation< std::is_same< ValueType, typename string_t::value_type >>, detail::negation< detail::is_basic_json< ValueType >>, detail::negation< std::is_same< ValueType, std::initializer_list< typename string_t::value_type >>>, detail::is_detected_lazy< detail::get_template_function, const basic_json_t &, ValueType > >::value, int >::type = 0> | |
JSON_EXPLICIT | operator ValueType () const |
get a value (implicit) More... | |
binary_t & | get_binary () |
const binary_t & | get_binary () const |
element access | |
reference | at (size_type idx) |
access specified array element with bounds checking More... | |
const_reference | at (size_type idx) const |
access specified array element with bounds checking More... | |
reference | at (const typename object_t::key_type &key) |
access specified object element with bounds checking More... | |
const_reference | at (const typename object_t::key_type &key) const |
access specified object element with bounds checking More... | |
reference | operator[] (size_type idx) |
access specified array element More... | |
const_reference | operator[] (size_type idx) const |
access specified array element More... | |
reference | operator[] (const typename object_t::key_type &key) |
access specified object element More... | |
const_reference | operator[] (const typename object_t::key_type &key) const |
read-only access specified object element More... | |
template<typename T > | |
reference | operator[] (T *key) |
access specified object element More... | |
template<typename T > | |
const_reference | operator[] (T *key) const |
read-only access specified object element More... | |
template<class ValueType , typename std::enable_if< detail::is_getable< basic_json_t, ValueType >::value &&!std::is_same< value_t, ValueType >::value, int >::type = 0> | |
ValueType | value (const typename object_t::key_type &key, const ValueType &default_value) const |
access specified object element with default value More... | |
string_t | value (const typename object_t::key_type &key, const char *default_value) const |
overload for a default value of type const char* More... | |
template<class ValueType , typename std::enable_if< detail::is_getable< basic_json_t, ValueType >::value, int >::type = 0> | |
ValueType | value (const json_pointer &ptr, const ValueType &default_value) const |
access specified object element via JSON Pointer with default value More... | |
string_t | value (const json_pointer &ptr, const char *default_value) const |
overload for a default value of type const char* More... | |
reference | front () |
access the first element More... | |
const_reference | front () const |
access the first element More... | |
reference | back () |
access the last element More... | |
const_reference | back () const |
access the last element More... | |
template<class IteratorType , typename std::enable_if< std::is_same< IteratorType, typename basic_json_t::iterator >::value||std::is_same< IteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0> | |
IteratorType | erase (IteratorType pos) |
remove element given an iterator More... | |
template<class IteratorType , typename std::enable_if< std::is_same< IteratorType, typename basic_json_t::iterator >::value||std::is_same< IteratorType, typename basic_json_t::const_iterator >::value, int >::type = 0> | |
IteratorType | erase (IteratorType first, IteratorType last) |
remove elements given an iterator range More... | |
size_type | erase (const typename object_t::key_type &key) |
remove element from a JSON object given a key More... | |
void | erase (const size_type idx) |
remove element from a JSON array given an index More... | |
lookup | |
template<typename KeyT > | |
iterator | find (KeyT &&key) |
find an element in a JSON object More... | |
template<typename KeyT > | |
const_iterator | find (KeyT &&key) const |
find an element in a JSON object More... | |
template<typename KeyT > | |
size_type | count (KeyT &&key) const |
returns the number of occurrences of a key in a JSON object More... | |
template<typename KeyT , typename std::enable_if< !std::is_same< typename std::decay< KeyT >::type, json_pointer >::value, int >::type = 0> | |
bool | contains (KeyT &&key) const |
check the existence of an element in a JSON object More... | |
bool | contains (const json_pointer &ptr) const |
check the existence of an element in a JSON object given a JSON pointer More... | |
iterators | |
static iteration_proxy< iterator > | iterator_wrapper (reference ref) noexcept |
wrapper to access iterator member functions in range-based for More... | |
static iteration_proxy< const_iterator > | iterator_wrapper (const_reference ref) noexcept |
wrapper to access iterator member functions in range-based for More... | |
iterator | begin () noexcept |
returns an iterator to the first element More... | |
const_iterator | begin () const noexcept |
returns a const iterator to the first element More... | |
const_iterator | cbegin () const noexcept |
returns a const iterator to the first element More... | |
iterator | end () noexcept |
returns an iterator to one past the last element More... | |
const_iterator | end () const noexcept |
returns a const iterator to one past the last element More... | |
const_iterator | cend () const noexcept |
returns a const iterator to one past the last element More... | |
reverse_iterator | rbegin () noexcept |
returns an iterator to the reverse-beginning More... | |
const_reverse_iterator | rbegin () const noexcept |
returns a const reverse iterator to the last element More... | |
reverse_iterator | rend () noexcept |
returns an iterator to the reverse-end More... | |
const_reverse_iterator | rend () const noexcept |
returns a const reverse iterator to one before the first More... | |
const_reverse_iterator | crbegin () const noexcept |
returns a const reverse iterator to the last element More... | |
const_reverse_iterator | crend () const noexcept |
returns a const reverse iterator to one before the first More... | |
iteration_proxy< iterator > | items () noexcept |
helper to access iterator member functions in range-based for More... | |
iteration_proxy< const_iterator > | items () const noexcept |
helper to access iterator member functions in range-based for More... | |
capacity | |
bool | empty () const noexcept |
checks whether the container is empty. More... | |
size_type | size () const noexcept |
returns the number of elements More... | |
size_type | max_size () const noexcept |
returns the maximum possible number of elements More... | |
modifiers | |
void | swap (reference left, reference right) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value) |
exchanges the values More... | |
void | clear () noexcept |
clears the contents More... | |
void | push_back (basic_json &&val) |
add an object to an array More... | |
reference | operator+= (basic_json &&val) |
add an object to an array More... | |
void | push_back (const basic_json &val) |
add an object to an array More... | |
reference | operator+= (const basic_json &val) |
add an object to an array More... | |
void | push_back (const typename object_t::value_type &val) |
add an object to an object More... | |
reference | operator+= (const typename object_t::value_type &val) |
add an object to an object More... | |
void | push_back (initializer_list_t init) |
add an object to an object More... | |
reference | operator+= (initializer_list_t init) |
add an object to an object More... | |
template<class... Args> | |
reference | emplace_back (Args &&... args) |
add an object to an array More... | |
template<class... Args> | |
std::pair< iterator, bool > | emplace (Args &&... args) |
add an object to an object if key does not exist More... | |
template<typename... Args> | |
iterator | insert_iterator (const_iterator pos, Args &&... args) |
iterator | insert (const_iterator pos, const basic_json &val) |
inserts element More... | |
iterator | insert (const_iterator pos, basic_json &&val) |
inserts element More... | |
iterator | insert (const_iterator pos, size_type cnt, const basic_json &val) |
inserts elements More... | |
iterator | insert (const_iterator pos, const_iterator first, const_iterator last) |
inserts elements More... | |
iterator | insert (const_iterator pos, initializer_list_t ilist) |
inserts elements More... | |
void | insert (const_iterator first, const_iterator last) |
inserts elements More... | |
void | update (const_reference j) |
updates a JSON object from another object, overwriting existing keys More... | |
void | update (const_iterator first, const_iterator last) |
updates a JSON object from another object, overwriting existing keys More... | |
void | swap (reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value) |
exchanges the values More... | |
void | swap (array_t &other) |
exchanges the values More... | |
void | swap (object_t &other) |
exchanges the values More... | |
void | swap (string_t &other) |
exchanges the values More... | |
void | swap (binary_t &other) |
exchanges the values More... | |
void | swap (typename binary_t::container_type &other) |
exchanges the values More... | |
lexicographical comparison operators | |
bool | operator== (const_reference lhs, const_reference rhs) noexcept |
comparison: equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator== (const_reference lhs, ScalarType rhs) noexcept |
comparison: equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator== (ScalarType lhs, const_reference rhs) noexcept |
comparison: equal More... | |
bool | operator!= (const_reference lhs, const_reference rhs) noexcept |
comparison: not equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator!= (const_reference lhs, ScalarType rhs) noexcept |
comparison: not equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator!= (ScalarType lhs, const_reference rhs) noexcept |
comparison: not equal More... | |
bool | operator< (const_reference lhs, const_reference rhs) noexcept |
comparison: less than More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator< (const_reference lhs, ScalarType rhs) noexcept |
comparison: less than More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator< (ScalarType lhs, const_reference rhs) noexcept |
comparison: less than More... | |
bool | operator<= (const_reference lhs, const_reference rhs) noexcept |
comparison: less than or equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator<= (const_reference lhs, ScalarType rhs) noexcept |
comparison: less than or equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator<= (ScalarType lhs, const_reference rhs) noexcept |
comparison: less than or equal More... | |
bool | operator> (const_reference lhs, const_reference rhs) noexcept |
comparison: greater than More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator> (const_reference lhs, ScalarType rhs) noexcept |
comparison: greater than More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator> (ScalarType lhs, const_reference rhs) noexcept |
comparison: greater than More... | |
bool | operator>= (const_reference lhs, const_reference rhs) noexcept |
comparison: greater than or equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator>= (const_reference lhs, ScalarType rhs) noexcept |
comparison: greater than or equal More... | |
template<typename ScalarType , typename std::enable_if< std::is_scalar< ScalarType >::value, int >::type = 0> | |
bool | operator>= (ScalarType lhs, const_reference rhs) noexcept |
comparison: greater than or equal More... | |
serialization | |
std::ostream & | operator<< (std::ostream &o, const basic_json &j) |
serialize to stream More... | |
std::ostream & | operator>> (const basic_json &j, std::ostream &o) |
serialize to stream More... | |
deserialization | |
std::istream & | operator<< (basic_json &j, std::istream &i) |
deserialize from stream More... | |
std::istream & | operator>> (std::istream &i, basic_json &j) |
deserialize from stream More... | |
template<typename InputType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | parse (InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false) |
deserialize from a compatible input More... | |
template<typename IteratorType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | parse (IteratorType first, IteratorType last, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false) |
deserialize from a pair of character iterators More... | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | parse (detail::span_input_adapter &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false) |
template<typename InputType > | |
static bool | accept (InputType &&i, const bool ignore_comments=false) |
check if the input is valid JSON More... | |
template<typename IteratorType > | |
static bool | accept (IteratorType first, IteratorType last, const bool ignore_comments=false) |
static JSON_HEDLEY_WARN_UNUSED_RESULT bool | accept (detail::span_input_adapter &&i, const bool ignore_comments=false) |
template<typename InputType , typename SAX > | |
static bool | sax_parse (InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false) |
generate SAX events More... | |
template<class IteratorType , class SAX > | |
static bool | sax_parse (IteratorType first, IteratorType last, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false) |
template<typename SAX > | |
static bool | sax_parse (detail::span_input_adapter &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false) |
binary serialization/deserialization support | |
static std::vector< std::uint8_t > | to_cbor (const basic_json &j) |
create a CBOR serialization of a given JSON value More... | |
static void | to_cbor (const basic_json &j, detail::output_adapter< std::uint8_t > o) |
static void | to_cbor (const basic_json &j, detail::output_adapter< char > o) |
static std::vector< std::uint8_t > | to_msgpack (const basic_json &j) |
create a MessagePack serialization of a given JSON value More... | |
static void | to_msgpack (const basic_json &j, detail::output_adapter< std::uint8_t > o) |
static void | to_msgpack (const basic_json &j, detail::output_adapter< char > o) |
static std::vector< std::uint8_t > | to_ubjson (const basic_json &j, const bool use_size=false, const bool use_type=false) |
create a UBJSON serialization of a given JSON value More... | |
static void | to_ubjson (const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false) |
static void | to_ubjson (const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false) |
static std::vector< std::uint8_t > | to_bson (const basic_json &j) |
Serializes the given JSON object j to BSON and returns a vector containing the corresponding BSON-representation. More... | |
static void | to_bson (const basic_json &j, detail::output_adapter< std::uint8_t > o) |
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the given output_adapter o . More... | |
static void | to_bson (const basic_json &j, detail::output_adapter< char > o) |
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the given output_adapter o . More... | |
template<typename InputType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_cbor (InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error) |
create a JSON value from an input in CBOR format More... | |
template<typename IteratorType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_cbor (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error) |
create a JSON value from an input in CBOR format More... | |
template<typename T > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_cbor (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error) |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_cbor (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error) |
template<typename InputType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_msgpack (InputType &&i, const bool strict=true, const bool allow_exceptions=true) |
create a JSON value from an input in MessagePack format More... | |
template<typename IteratorType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_msgpack (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true) |
create a JSON value from an input in MessagePack format More... | |
template<typename T > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_msgpack (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true) |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_msgpack (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true) |
template<typename InputType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_ubjson (InputType &&i, const bool strict=true, const bool allow_exceptions=true) |
create a JSON value from an input in UBJSON format More... | |
template<typename IteratorType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_ubjson (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true) |
create a JSON value from an input in UBJSON format More... | |
template<typename T > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_ubjson (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true) |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_ubjson (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true) |
template<typename InputType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_bson (InputType &&i, const bool strict=true, const bool allow_exceptions=true) |
Create a JSON value from an input in BSON format. More... | |
template<typename IteratorType > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_bson (IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true) |
Create a JSON value from an input in BSON format. More... | |
template<typename T > | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_bson (const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true) |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | from_bson (detail::span_input_adapter &&i, const bool strict=true, const bool allow_exceptions=true) |
JSON Pointer functions | |
reference | operator[] (const json_pointer &ptr) |
access specified element via JSON Pointer More... | |
const_reference | operator[] (const json_pointer &ptr) const |
access specified element via JSON Pointer More... | |
reference | at (const json_pointer &ptr) |
access specified element via JSON Pointer More... | |
const_reference | at (const json_pointer &ptr) const |
access specified element via JSON Pointer More... | |
basic_json | flatten () const |
return flattened JSON value More... | |
basic_json | unflatten () const |
unflatten a previously flattened JSON value More... | |
JSON Patch functions | |
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json | diff (const basic_json &source, const basic_json &target, const std::string &path="") |
creates a diff as a JSON patch More... | |
basic_json | patch (const basic_json &json_patch) const |
applies a JSON patch More... | |
JSON Merge Patch functions | |
void | merge_patch (const basic_json &apply_patch) |
applies a JSON Merge Patch More... | |
a class to store JSON values
ObjectType | type for JSON objects (std::map by default; will be used in object_t) |
ArrayType | type for JSON arrays (std::vector by default; will be used in array_t) |
StringType | type for JSON strings and object keys (std::string by default; will be used in string_t) |
BooleanType | type for JSON booleans (bool by default; will be used in boolean_t) |
NumberIntegerType | type for JSON integer numbers (int64_t by default; will be used in number_integer_t) |
NumberUnsignedType | type for JSON unsigned integer numbers ( by default; will be used in number_unsigned_t) |
NumberFloatType | type for JSON floating-point numbers (double by default; will be used in number_float_t) |
BinaryType | type for packed binary data for compatibility with binary serialization formats (std::vector<std::uint8_t> by default; will be used in binary_t) |
AllocatorType | type of the allocator to use (std::allocator by default) |
JSONSerializer | the serializer to resolve internal calls to to_json() and from_json() (adl_serializer by default) |
@requirement The class satisfies the following concept requirements:
==
, see operator==(const_reference,const_reference).<
, see operator<(const_reference,const_reference).std::nullptr_t
objects which are used to model the null
value.m_type == value_t::object
, then m_value.object != nullptr
.m_type == value_t::array
, then m_value.array != nullptr
.m_type == value_t::string
, then m_value.string != nullptr
. The invariants are checked by member function assert_invariant().using nlohmann::basic_json::allocator_type = AllocatorType<basic_json> |
using nlohmann::basic_json::array_t = ArrayType<basic_json, AllocatorType<basic_json> > |
a type for an array
RFC 8259 describes JSON arrays as follows:
An array is an ordered sequence of zero or more values.
To store objects in C++, a type is defined by the template parameters explained below.
ArrayType | container type to store arrays (e.g., std::vector or std::list ) |
AllocatorType | allocator to use for arrays (e.g., std::allocator ) |
With the default values for ArrayType (std::vector
) and AllocatorType (std::allocator
), the default value for array_t is:
RFC 8259 specifies:
An implementation may set limits on the maximum depth of nesting.
In this class, the array's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the max_size function of a JSON array.
Arrays are stored as pointers in a basic_json type. That is, for any access to array values, a pointer of type array_t*
must be dereferenced.
|
private |
|
private |
using nlohmann::basic_json::binary_t = nlohmann::byte_container_with_subtype<BinaryType> |
a type for a packed binary type
This type is a type designed to carry binary data that appears in various serialized formats, such as CBOR's Major Type 2, MessagePack's bin, and BSON's generic binary subtype. This type is NOT a part of standard JSON and exists solely for compatibility with these binary types. As such, it is simply defined as an ordered sequence of zero or more byte values.
Additionally, as an implementation detail, the subtype of the binary data is carried around as a std::uint8_t
, which is compatible with both of the binary data formats that use binary subtyping, (though the specific numbering is incompatible with each other, and it is up to the user to translate between them).
CBOR's RFC 7049 describes this type as:
Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers (major type 0).
MessagePack's documentation on the bin type family describes this type as:
Bin format family stores an byte array in 2, 3, or 5 bytes of extra bytes in addition to the size of the byte array.
BSON's specifications describe several binary types; however, this type is intended to represent the generic binary type which has the description:
Generic binary subtype - This is the most commonly used binary subtype and should be the 'default' for drivers and tools.
None of these impose any limitations on the internal representation other than the basic unit of storage be some type of array whose parts are decomposable into bytes.
The default representation of this binary format is a std::vector<std::uint8_t>
, which is a very common way to represent a byte array in modern C++.
The default values for BinaryType is std::vector<std::uint8_t>
Binary Arrays are stored as pointers in a basic_json type. That is, for any access to array values, a pointer of the type binary_t*
must be dereferenced.
|
private |
using nlohmann::basic_json::boolean_t = BooleanType |
a type for a boolean
RFC 8259 implicitly describes a boolean as a type which differentiates the two literals true
and false
.
To store objects in C++, a type is defined by the template parameter BooleanType which chooses the type to use.
With the default values for BooleanType (bool
), the default value for boolean_t is:
Boolean values are stored directly inside a basic_json type.
using nlohmann::basic_json::const_iterator = iter_impl<const basic_json> |
a const iterator for a basic_json container
using nlohmann::basic_json::const_pointer = typename std::allocator_traits<allocator_type>::const_pointer |
using nlohmann::basic_json::const_reference = const value_type& |
using nlohmann::basic_json::const_reverse_iterator = json_reverse_iterator<typename basic_json::const_iterator> |
a const reverse iterator for a basic_json container
using nlohmann::basic_json::difference_type = std::ptrdiff_t |
general exception of the basic_json class
This class is an extension of std::exception
objects with a member id for exception ids. It is used as the base class for all exceptions thrown by the basic_json class. This class can hence be used as "wildcard" to catch exceptions.
Subclasses:
std::runtime_error
which can cope with arbitrary-length error messages. Intermediate strings are built with static functions and then passed to the actual constructor. @liveexample{The following code shows how arbitrary library exceptions can be caught.,exception}
using nlohmann::basic_json::initializer_list_t = std::initializer_list<detail::json_ref<basic_json> > |
helper type for initializer lists of basic_json values
|
private |
exception indicating errors with iterators
This exception is thrown if iterators passed to a library function do not match the expected semantics.
Exceptions have ids 2xx.
name / id | example message | description |
---|---|---|
json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (first, last) is invalid. |
json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. |
json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from. |
json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (begin(), end()), because this is the only way the single stored value is expressed. All other ranges are invalid. |
json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the begin() iterator, because it is the only way to address the stored value. All other iterators are invalid. |
json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range. |
json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key. |
json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. |
json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. |
json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (first, last) is invalid. |
json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to. |
json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container. |
json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered. |
json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to begin(). |
@liveexample{The following code shows how an invalid_iterator
exception can be caught.,invalid_iterator}
|
private |
|
private |
an iterator for a basic_json container
JSON Pointer, see nlohmann::json_pointer.
|
private |
SAX interface type, see nlohmann::json_sax.
using nlohmann::basic_json::json_serializer = JSONSerializer<T, SFINAE> |
using nlohmann::basic_json::number_float_t = NumberFloatType |
a type for a number (floating-point)
RFC 8259 describes numbers as follows:
The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed. (...) Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.
This description includes both integer and floating-point numbers. However, C++ allows more precise storage if it is known whether the number is a signed integer, an unsigned integer or a floating-point number. Therefore, three different types, number_integer_t, number_unsigned_t and number_float_t are used.
To store floating-point numbers in C++, a type is defined by the template parameter NumberFloatType which chooses the type to use.
With the default values for NumberFloatType (double
), the default value for number_float_t is:
01.2
will be serialized to 1.2
. During deserialization, leading zeros yield an error.null
.RFC 8259 states:
This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754-2008 binary64 (double precision) numbers is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision.
This implementation does exactly follow this approach, as it uses double precision floating-point numbers. Note values smaller than -1.79769313486232e+308
and values greater than 1.79769313486232e+308
will be stored as NaN internally and be serialized to null
.
Floating-point number values are stored directly inside a basic_json type.
using nlohmann::basic_json::number_integer_t = NumberIntegerType |
a type for a number (integer)
RFC 8259 describes numbers as follows:
The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed. (...) Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.
This description includes both integer and floating-point numbers. However, C++ allows more precise storage if it is known whether the number is a signed integer, an unsigned integer or a floating-point number. Therefore, three different types, number_integer_t, number_unsigned_t and number_float_t are used.
To store integer numbers in C++, a type is defined by the template parameter NumberIntegerType which chooses the type to use.
With the default values for NumberIntegerType (int64_t
), the default value for number_integer_t is:
010
will be serialized to 8
. During deserialization, leading zeros yield an error.null
.RFC 8259 specifies:
An implementation may set limits on the range and precision of numbers.
When the default type is used, the maximal integer number that can be stored is 9223372036854775807
(INT64_MAX) and the minimal integer number that can be stored is -9223372036854775808
(INT64_MIN). Integer numbers that are out of range will yield over/underflow when used in a constructor. During deserialization, too large or small integer numbers will be automatically be stored as number_unsigned_t or number_float_t.
RFC 8259 further states:
Note that when such software is used, numbers that are integers and are in the range are interoperable in the sense that implementations will agree exactly on their numeric values.
As this range is a subrange of the exactly supported range [INT64_MIN, INT64_MAX], this class's integer type is interoperable.
Integer number values are stored directly inside a basic_json type.
using nlohmann::basic_json::number_unsigned_t = NumberUnsignedType |
a type for a number (unsigned)
RFC 8259 describes numbers as follows:
The representation of numbers is similar to that used in most programming languages. A number is represented in base 10 using decimal digits. It contains an integer component that may be prefixed with an optional minus sign, which may be followed by a fraction part and/or an exponent part. Leading zeros are not allowed. (...) Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.
This description includes both integer and floating-point numbers. However, C++ allows more precise storage if it is known whether the number is a signed integer, an unsigned integer or a floating-point number. Therefore, three different types, number_integer_t, number_unsigned_t and number_float_t are used.
To store unsigned integer numbers in C++, a type is defined by the template parameter NumberUnsignedType which chooses the type to use.
With the default values for NumberUnsignedType (uint64_t
), the default value for number_unsigned_t is:
010
will be serialized to 8
. During deserialization, leading zeros yield an error.null
.RFC 8259 specifies:
An implementation may set limits on the range and precision of numbers.
When the default type is used, the maximal integer number that can be stored is 18446744073709551615
(UINT64_MAX) and the minimal integer number that can be stored is 0
. Integer numbers that are out of range will yield over/underflow when used in a constructor. During deserialization, too large or small integer numbers will be automatically be stored as number_integer_t or number_float_t.
RFC 8259 further states:
Note that when such software is used, numbers that are integers and are in the range are interoperable in the sense that implementations will agree exactly on their numeric values.
As this range is a subrange (when considered in conjunction with the number_integer_t type) of the exactly supported range [0, UINT64_MAX], this class's integer type is interoperable.
Integer number values are stored directly inside a basic_json type.
using nlohmann::basic_json::object_comparator_t = std::less<StringType> |
using nlohmann::basic_json::object_t = ObjectType<StringType, basic_json, object_comparator_t, AllocatorType<std::pair<const StringType, basic_json> >> |
a type for an object
RFC 8259 describes JSON objects as follows:
An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.
To store objects in C++, a type is defined by the template parameters described below.
ObjectType | the container to store objects (e.g., std::map or std::unordered_map ) |
StringType | the type of the keys or names (e.g., std::string ). The comparison function std::less<StringType> is used to order elements inside the container. |
AllocatorType | the allocator to use for objects (e.g., std::allocator ) |
With the default values for ObjectType (std::map
), StringType (std::string
), and AllocatorType (std::allocator
), the default value for object_t is:
The choice of object_t influences the behavior of the JSON class. With the default type, objects have the following behavior:
{"key": 2, "key": 1}
could be equal to either {"key": 1}
or {"key": 2}
.{"b": 1, "a": 2}
and {"a": 2, "b": 1}
will be stored and serialized as {"a": 2, "b": 1}
.{"b": 1, "a": 2}
and {"a": 2, "b": 1}
will be treated as equal.RFC 8259 specifies:
An implementation may set limits on the maximum depth of nesting.
In this class, the object's limit of nesting is not explicitly constrained. However, a maximum depth of nesting may be introduced by the compiler or runtime environment. A theoretical limit can be queried by calling the max_size function of a JSON object.
Objects are stored as pointers in a basic_json type. That is, for any access to object values, a pointer of type object_t*
must be dereferenced.
std::map
with std::less
is used by default. Please note this behavior conforms to RFC 8259, because any order implements the specified "unordered" nature of JSON objects. exception indicating other library errors
This exception is thrown in case of errors that cannot be classified with the other exception types.
Exceptions have ids 5xx.
name / id | example message | description |
---|---|---|
json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. |
@liveexample{The following code shows how an other_error
exception can be caught.,other_error}
exception indicating access out of the defined range
This exception is thrown in case a library function is called on an input parameter that exceeds the expected range, for instance in case of array indices or nonexisting object keys.
Exceptions have ids 4xx.
name / id | example message | description |
---|---|---|
json.exception.out_of_range.401 | array index 3 is out of range | The provided array index i is larger than size-1. |
json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index - in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. |
json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. |
json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. |
json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. |
json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. |
json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. (until version 3.8.0) |
json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following # ) of an UBJSON array or object exceeds the maximal capacity. |
json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string |
@liveexample{The following code shows how an out_of_range
exception can be caught.,out_of_range}
|
private |
exception indicating a parse error
This exception is thrown by the library when a parse error occurs. Parse errors can occur during the deserialization of JSON text, CBOR, MessagePack, as well as when using JSON Patch.
Member byte holds the byte index of the last read character in the input file.
Exceptions have ids 1xx.
name / id | example message | description |
---|---|---|
json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member byte indicates the error position. |
json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the \uxxxx format to describe Unicode characters. Code points above above 0xFFFF are split into two \uxxxx entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. |
json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. |
json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | RFC 6902 requires a JSON Patch document to be a JSON document that represents an array of objects. |
json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. |
json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer (RFC 6901) may be 0 or any number without a leading 0 . |
json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a / character. |
json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only ~0 and ~1 are valid escape sequences. |
json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number. |
json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. |
json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. |
json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read. |
json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet). |
json.exception.parse_error.115 | parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A | A UBJSON high-precision number could not be parsed. |
@liveexample{The following code shows how a parse_error
exception can be caught.,parse_error}
parser event types
The parser callback distinguishes the following events:
object_start
: the parser read {
and started to process a JSON objectkey
: the parser read a key of a value in an objectobject_end
: the parser read }
and finished processing a JSON objectarray_start
: the parser read [
and started to process a JSON arrayarray_end
: the parser read ]
and finished processing a JSON arrayvalue
: the parser finished reading a JSON valueper-element parser callback type
With a parser callback function, the result of parsing a JSON text can be influenced. When passed to parse, it is called on certain events (passed as parse_event_t via parameter event) with a set recursion depth depth and context JSON value parsed. The return value of the callback function is a boolean indicating whether the element that emitted the callback shall be kept or not.
We distinguish six scenarios (determined by the event type) in which the callback function can be called. The following table describes the values of the parameters depth, event, and parsed.
parameter event | description | parameter depth | parameter parsed |
---|---|---|---|
parse_event_t::object_start | the parser read { and started to process a JSON object | depth of the parent of the JSON object | a JSON value with type discarded |
parse_event_t::key | the parser read a key of a value in an object | depth of the currently parsed JSON object | a JSON string containing the key |
parse_event_t::object_end | the parser read } and finished processing a JSON object | depth of the parent of the JSON object | the parsed JSON object |
parse_event_t::array_start | the parser read [ and started to process a JSON array | depth of the parent of the JSON array | a JSON value with type discarded |
parse_event_t::array_end | the parser read ] and finished processing a JSON array | depth of the parent of the JSON array | the parsed JSON array |
parse_event_t::value | the parser finished reading a JSON value | depth of the value | the parsed JSON value |
Discarding a value (i.e., returning false
) has different effects depending on the context in which function was called:
null
. This case happens if the top-level element is skipped.[in] | depth | the depth of the recursion during parsing |
[in] | event | an event of type parse_event_t indicating the context in the callback function has been called |
[in,out] | parsed | the current intermediate parse result; note that writing to this value has no effect for parse_event_t::key events |
true
) or not (false
). In the latter case, it is either skipped completely or replaced by an empty discarded object.using nlohmann::basic_json::pointer = typename std::allocator_traits<allocator_type>::pointer |
using nlohmann::basic_json::reverse_iterator = json_reverse_iterator<typename basic_json::iterator> |
a reverse iterator for a basic_json container
using nlohmann::basic_json::size_type = std::size_t |
using nlohmann::basic_json::string_t = StringType |
a type for a string
RFC 8259 describes JSON strings as follows:
A string is a sequence of zero or more Unicode characters.
To store objects in C++, a type is defined by the template parameter described below. Unicode values are split by the JSON class into byte-sized characters during deserialization.
StringType | the container to store strings (e.g., std::string ). Note this container is used for keys/names in objects, see object_t. |
With the default values for StringType (std::string
), the default value for string_t is:
Strings are stored in UTF-8 encoding. Therefore, functions like std::string::size()
or std::string::length()
return the number of bytes in the string rather than the number of characters or glyphs.
RFC 8259 states:
Software implementations are typically required to test names of object members for equality. Implementations that transform the textual representation into sequences of Unicode code units and then perform the comparison numerically, code unit by code unit, are interoperable in the sense that implementations will agree in all cases on equality or inequality of two strings. For example, implementations that compare strings with escaped characters unconverted may incorrectly find that
"a\\b"
and"a\u005Cb"
are not equal.
This implementation is interoperable as it does compare strings code unit by code unit.
String values are stored as pointers in a basic_json type. That is, for any access to string values, a pointer of type string_t*
must be dereferenced.
exception indicating executing a member function with a wrong type
This exception is thrown in case of a type error; that is, a library function is executed on a JSON value whose type does not match the expected semantics.
Exceptions have ids 3xx.
name / id | example message | description |
---|---|---|
json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. |
json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. |
json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a basic_json object with get_ref, the type of the reference must match the value type. For instance, for a JSON array, the ReferenceType must be array_t &. |
json.exception.type_error.304 | cannot use at() with string | The at() member functions can only be executed for certain JSON types. |
json.exception.type_error.305 | cannot use operator[] with string | The operator[] member functions can only be executed for certain JSON types. |
json.exception.type_error.306 | cannot use value() with string | The value() member functions can only be executed for certain JSON types. |
json.exception.type_error.307 | cannot use erase() with string | The erase() member functions can only be executed for certain JSON types. |
json.exception.type_error.308 | cannot use push_back() with string | The push_back() and operator+= member functions can only be executed for certain JSON types. |
json.exception.type_error.309 | cannot use insert() with | The insert() member functions can only be executed for certain JSON types. |
json.exception.type_error.310 | cannot use swap() with number | The swap() member functions can only be executed for certain JSON types. |
json.exception.type_error.311 | cannot use emplace_back() with string | The emplace_back() member function can only be executed for certain JSON types. |
json.exception.type_error.312 | cannot use update() with string | The update() member functions can only be executed for certain JSON types. |
json.exception.type_error.313 | invalid value to unflatten | The unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. |
json.exception.type_error.314 | only objects can be unflattened | The unflatten function only works for an object whose keys are JSON Pointers. |
json.exception.type_error.315 | values in object must be primitive | The unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive. |
json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The dump function only works with UTF-8 encoded strings; that is, if you assign a std::string to a JSON value, make sure it is UTF-8 encoded. |
json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw true or null JSON object cannot be serialized to BSON) |
@liveexample{The following code shows how a type_error
exception can be caught.,type_error}
the type of elements in a basic_json container
|
inline |
create an empty value with a given type
Create an empty JSON value with a given type. The value will be default initialized with an empty value which depends on the type:
Value type | initial value |
---|---|
null | null |
boolean | false |
string | "" |
number | 0 |
object | {} |
array | [] |
binary | empty array |
[in] | v | the type of the value to create |
@complexity Constant.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
@liveexample{The following code shows the constructor for different value_t values,basic_json__value_t}
Definition at line 18840 of file json.hpp.
References assert_invariant().
Referenced by basic_json(), binary(), from_bson(), from_cbor(), from_msgpack(), from_ubjson(), json_value(), and push_back().
|
inlinenoexcept |
create a null object
Create a null
JSON value. It either takes a null pointer as parameter (explicitly creating null
) or no parameter (implicitly creating null
). The passed null pointer itself is not read – it is only used to choose the right constructor.
@complexity Constant.
@exceptionsafety No-throw guarantee: this constructor never throws exceptions.
@liveexample{The following code shows the constructor with and without a null pointer parameter.,basic_json__nullptr_t}
Definition at line 18864 of file json.hpp.
References assert_invariant().
|
inlinenoexcept |
create a JSON value
This is a "catch all" constructor for all compatible JSON types; that is, types for which a to_json()
method exists. The constructor forwards the parameter val to that method (to json_serializer<U>::to_json
method with U = uncvref_t<CompatibleType>
, to be exact).
Template type CompatibleType includes, but is not limited to, the following types:
std::vector
, std::deque
, std::list
, std::forward_list
, std::array
, std::valarray
, std::set
, std::unordered_set
, std::multiset
, and std::unordered_multiset
with a value_type
from which a basic_json value can be constructed.std::map
, std::unordered_map
, std::multimap
, and std::unordered_multimap
with a key_type
compatible to string_t and a value_type
from which a basic_json value can be constructed.int
, size_t
, int64_t
, float
or double
can be used.bool
can be used.std::vector<std::uint8_t>
may be used, unfortunately because string literals cannot be distinguished from binary character arrays by the C++ type system, all types compatible with const char*
will be directed to the string constructor instead. This is both for backwards compatibility, and due to the fact that a binary type is not a standard JSON type.See the examples below.
CompatibleType | a type such that:
|
U | = uncvref_t<CompatibleType> |
[in] | val | the value to be forwarded to the respective constructor |
@complexity Usually linear in the size of the passed val, also depending on the implementation of the called to_json()
method.
@exceptionsafety Depends on the called constructor. For types directly supported by the library (i.e., all types for which no to_json()
function was provided), strong guarantee holds: if an exception is thrown, there are no changes to any JSON value.
@liveexample{The following code shows the constructor with several compatible types.,basic_json__CompatibleType}
Definition at line 18936 of file json.hpp.
References assert_invariant(), set_parents(), and nlohmann::detail::to_json().
|
inline |
create a JSON value from an existing one
This is a constructor for existing basic_json types. It does not hijack copy/move constructors, since the parameter has different template arguments than the current ones.
The constructor tries to convert the internal m_value of the parameter.
BasicJsonType | a type such that:
|
[in] | val | the basic_json value to be converted. |
@complexity Usually linear in the size of the passed val, also depending on the implementation of the called to_json()
method.
@exceptionsafety Depends on the called constructor. For types directly supported by the library (i.e., all types for which no to_json()
function was provided), strong guarantee holds: if an exception is thrown, there are no changes to any JSON value.
Definition at line 18974 of file json.hpp.
References nlohmann::detail::array, assert_invariant(), nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::discarded, JSON_ASSERT, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, set_parents(), nlohmann::detail::string, and nlohmann::detail::to_json().
|
inline |
create a container (array or object) from an initializer list
Creates a JSON value of type array or object from the passed initializer list init. In case type_deduction is true
(default), the type of the JSON value to be created is deducted from the initializer list init according to the following rules:
{}
is created.The rules aim to create the best fit between a C++ initializer list and JSON values. The rationale is as follows:
{}
which is exactly an empty JSON object.With the rules described above, the following JSON values cannot be expressed by an initializer list:
[]
): use array(initializer_list_t) with an empty initializer list in this case[in] | init | initializer list with JSON values |
[in] | type_deduction | internal parameter; when set to true , the type of the JSON value is deducted from the initializer list init; when set to false , the type provided via manual_type is forced. This mode is used by the functions array(initializer_list_t) and object(initializer_list_t). |
[in] | manual_type | internal parameter; when type_deduction is set to false , the created JSON value will use the provided type (only value_t::array and value_t::object are valid); when type_deduction is set to true , this parameter has no effect |
type_error.301 | if type_deduction is false , manual_type is value_t::object , but init contains an element which is not a pair whose first element is a string. In this case, the constructor could not create an object. If type_deduction would have be true , an array would have been created. See object(initializer_list_t) for an example. |
@complexity Linear in the size of the initializer list init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
@liveexample{The example below shows how JSON values are created from initializer lists.,basic_json__list_init_t}
Definition at line 19098 of file json.hpp.
References nlohmann::detail::array, assert_invariant(), basic_json(), nlohmann::detail::type_error::create(), board::element, init(), JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, nlohmann::detail::json_ref< BasicJsonType >::moved_or_copied(), nlohmann::detail::object, and set_parents().
|
inline |
construct an array with count copies of given value
Constructs a JSON array value by creating cnt copies of a passed value. In case cnt is 0
, an empty array is created.
[in] | cnt | the number of JSON copies of val to create |
[in] | val | the JSON value to copy |
@complexity Linear in cnt.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
@liveexample{The following code shows examples for the basic_json(size_type\, const basic_json&) constructor.,basic_json__size_type_basic_json}
Definition at line 19353 of file json.hpp.
References assert_invariant(), m_value, and set_parents().
|
inline |
construct a JSON container given an iterator range
Constructs the JSON value with the contents of the range [first, last)
. The semantics depends on the different types a JSON value can have:
begin()
and last must be end()
. In this case, the value is copied. Otherwise, invalid_iterator.204 is thrown.std::vector
or std::map
; that is, a JSON array or object is constructed from the values in the range.InputIT | an input iterator type (iterator or const_iterator) |
[in] | first | begin of the range to copy from (included) |
[in] | last | end of the range to copy from (excluded) |
[first, last)
is valid. Usually, this precondition cannot be checked efficiently. Only certain edge cases are detected; see the description of the exceptions below. A violation of this precondition yields undefined behavior.std::abort
if this precondition is not met. Assertions can be disabled by defining NDEBUG
at compile time. See https://en.cppreference.com/w/cpp/error/assert for more information.invalid_iterator.201 | if iterators first and last are not compatible (i.e., do not belong to the same JSON value). In this case, the range [first, last) is undefined. |
invalid_iterator.204 | if iterators first and last belong to a primitive type (number, boolean, or string), but first does not point to the first element any more. In this case, the range [first, last) is undefined. See example code below. |
invalid_iterator.206 | if iterators first and last belong to a null value. In this case, the range [first, last) is undefined. |
@complexity Linear in distance between first and last.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
@liveexample{The example below shows several ways to create JSON values by specifying a subrange with iterators.,basic_json__InputIt_InputIt}
Definition at line 19419 of file json.hpp.
References nlohmann::detail::array, assert_invariant(), basic_json(), nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::discarded, JSON_ASSERT, JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, set_parents(), and nlohmann::detail::string.
|
inline |
|
inline |
copy constructor
Creates a copy of a given JSON value.
[in] | other | the JSON value to copy |
*this == other
@complexity Linear in the size of other.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
@requirement This function helps basic_json
satisfying the Container requirements:
other == basic_json(other)
.@liveexample{The following code shows an example for the copy constructor.,basic_json__basic_json}
Definition at line 19556 of file json.hpp.
References nlohmann::detail::array, assert_invariant(), nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::discarded, m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, set_parents(), and nlohmann::detail::string.
|
inlinenoexcept |
move constructor
Move constructor. Constructs a JSON value with the contents of the given value other using move semantics. It "steals" the resources from other and leaves it as JSON null value.
[in,out] | other | value to move to this object |
*this
has the same value as other before the call. @complexity Constant.
@exceptionsafety No-throw guarantee: this constructor never throws exceptions.
@requirement This function helps basic_json
satisfying the MoveConstructible requirements.
@liveexample{The code below shows the move constructor explicitly called via std::move.,basic_json__moveconstructor}
Definition at line 19648 of file json.hpp.
References assert_invariant(), nlohmann::detail::null, and set_parents().
|
inlinenoexcept |
destructor
Destroys the JSON value and frees all allocated memory.
@complexity Linear.
@requirement This function helps basic_json
satisfying the Container requirements:
Definition at line 19720 of file json.hpp.
References assert_invariant(), and m_value.
|
inlinestatic |
|
inlinestatic |
check if the input is valid JSON
Unlike the parse(InputType&&, const parser_callback_t,const bool) function, this function neither throws an exception in case of invalid JSON input (i.e., a parse error) nor creates diagnostic information.
InputType | A compatible input, for instance
|
[in] | i | input to read from |
[in] | ignore_comments | whether comments should be ignored and treated like whitespace (true) or yield a parse error (true); (optional, false by default) |
@complexity Linear in the length of the input. The parser is a predictive LL(1) parser.
@liveexample{The example below demonstrates the accept()
function reading from a string.,accept__string}
Definition at line 24339 of file json.hpp.
References nlohmann::detail::input_adapter(), and parser().
|
inlinestatic |
Definition at line 24346 of file json.hpp.
References nlohmann::detail::input_adapter(), and parser().
|
inlinestatic |
explicitly create an array from an initializer list
Creates a JSON array value from a given initializer list. That is, given a list of values a, b, c
, creates the JSON value [a, b, c]
. If the initializer list is empty, the empty array []
is created.
[in] | init | initializer list with JSON values to create an array from (optional) |
@complexity Linear in the size of init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
@liveexample{The following code shows an example for the array
function.,array}
|
inlineprivatenoexcept |
checks the class invariants
This function asserts the class invariants. It needs to be called at the end of every constructor to make sure that created objects respect the invariant. Furthermore, it has to be called each time the type of a JSON value is changed, because the invariant expresses a relationship between m_type and m_value.
Furthermore, the parent relation is checked for arrays and objects: If check_parents true and the value is an array or object, then the container's elements must have the current value as parent.
[in] | check_parents | whether the parent relation should be checked. The value is true by default and should only be set to false during destruction of objects when the invariant does not need to hold. |
Definition at line 18634 of file json.hpp.
References nlohmann::detail::array, begin(), nlohmann::detail::binary, end(), is_structured(), JSON_ASSERT, JSON_CATCH, JSON_TRY, m_value, nlohmann::detail::object, and nlohmann::detail::string.
Referenced by basic_json(), emplace(), emplace_back(), erase(), operator=(), operator[](), push_back(), swap(), update(), and ~basic_json().
|
inline |
access specified element via JSON Pointer
Returns a reference to the element at with specified JSON pointer ptr, with bounds checking.
[in] | ptr | JSON pointer to the desired element |
parse_error.106 | if an array index in the passed JSON pointer ptr begins with '0'. See example below. |
parse_error.109 | if an array index in the passed JSON pointer ptr is not a number. See example below. |
out_of_range.401 | if an array index in the passed JSON pointer ptr is out of range. See example below. |
out_of_range.402 | if the array index '-' is used in the passed JSON pointer ptr. As at provides checked access (and no elements are implicitly inserted), the index '-' is always invalid. See example below. |
out_of_range.403 | if the JSON pointer describes a key of an object which cannot be found. See example below. |
out_of_range.404 | if the JSON pointer ptr can not be resolved. See example below. |
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@complexity Constant.
@liveexample{The behavior is shown in the example.,at_json_pointer}
|
inline |
access specified element via JSON Pointer
Returns a const reference to the element at with specified JSON pointer ptr, with bounds checking.
[in] | ptr | JSON pointer to the desired element |
parse_error.106 | if an array index in the passed JSON pointer ptr begins with '0'. See example below. |
parse_error.109 | if an array index in the passed JSON pointer ptr is not a number. See example below. |
out_of_range.401 | if an array index in the passed JSON pointer ptr is out of range. See example below. |
out_of_range.402 | if the array index '-' is used in the passed JSON pointer ptr. As at provides checked access (and no elements are implicitly inserted), the index '-' is always invalid. See example below. |
out_of_range.403 | if the JSON pointer describes a key of an object which cannot be found. See example below. |
out_of_range.404 | if the JSON pointer ptr can not be resolved. See example below. |
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@complexity Constant.
@liveexample{The behavior is shown in the example.,at_json_pointer_const}
|
inline |
access specified object element with bounds checking
Returns a reference to the element at with specified key key, with bounds checking.
[in] | key | key of the element to access |
type_error.304 | if the JSON value is not an object; in this case, calling at with a key makes no sense. See example below. |
out_of_range.403 | if the key key is is not stored in the object; that is, find(key) == end() . See example below. |
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be read and written using at()
. It also demonstrates the different exceptions that can be thrown.,at__object_t_key_type}
Definition at line 20950 of file json.hpp.
References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), is_object(), JSON_CATCH, JSON_HEDLEY_LIKELY, JSON_THROW, JSON_TRY, m_value, set_parent(), and type_name().
|
inline |
access specified object element with bounds checking
Returns a const reference to the element at with specified key key, with bounds checking.
[in] | key | key of the element to access |
type_error.304 | if the JSON value is not an object; in this case, calling at with a key makes no sense. See example below. |
out_of_range.403 | if the key key is is not stored in the object; that is, find(key) == end() . See example below. |
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be read using at()
. It also demonstrates the different exceptions that can be thrown., at__object_t_key_type_const}
Definition at line 21001 of file json.hpp.
References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), is_object(), JSON_CATCH, JSON_HEDLEY_LIKELY, JSON_THROW, JSON_TRY, m_value, and type_name().
access specified array element with bounds checking
Returns a reference to the element at specified location idx, with bounds checking.
[in] | idx | index of the element to access |
type_error.304 | if the JSON value is not an array; in this case, calling at with an index makes no sense. See example below. |
out_of_range.401 | if the index idx is out of range of the array; that is, idx >= size() . See example below. |
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@complexity Constant.
@liveexample{The example below shows how array elements can be read and written using at()
. It also demonstrates the different exceptions that can be thrown.,at__size_type}
Definition at line 20852 of file json.hpp.
References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), is_array(), JSON_CATCH, JSON_HEDLEY_LIKELY, JSON_THROW, JSON_TRY, m_value, set_parent(), nlohmann::to_string(), and type_name().
|
inline |
access specified array element with bounds checking
Returns a const reference to the element at specified location idx, with bounds checking.
[in] | idx | index of the element to access |
type_error.304 | if the JSON value is not an array; in this case, calling at with an index makes no sense. See example below. |
out_of_range.401 | if the index idx is out of range of the array; that is, idx >= size() . See example below. |
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@complexity Constant.
@liveexample{The example below shows how array elements can be read using at()
. It also demonstrates the different exceptions that can be thrown., at__size_type_const}
Definition at line 20899 of file json.hpp.
References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), is_array(), JSON_CATCH, JSON_HEDLEY_LIKELY, JSON_THROW, JSON_TRY, m_value, nlohmann::to_string(), and type_name().
|
inline |
access the last element
Returns a reference to the last element in the container. For a JSON container c
, the expression c.back()
is equivalent to
@complexity Constant.
null
(would throw std::out_of_range
) or an empty array or object (undefined behavior, guarded by assertions). invalid_iterator.214 | when called on a null value. See example below. |
@liveexample{The following code shows an example for back()
.,back}
Definition at line 21515 of file json.hpp.
References end(), and Ice::tmp.
|
inline |
access the last element
Returns a reference to the last element in the container. For a JSON container c
, the expression c.back()
is equivalent to
@complexity Constant.
null
(would throw std::out_of_range
) or an empty array or object (undefined behavior, guarded by assertions). invalid_iterator.214 | when called on a null value. See example below. |
@liveexample{The following code shows an example for back()
.,back}
Definition at line 21525 of file json.hpp.
References cend(), and Ice::tmp.
|
inlinenoexcept |
returns a const iterator to the first element
Returns a const iterator to the first element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the Container requirements:
const_cast<const basic_json&>(*this).begin()
.@liveexample{The following code shows an example for cbegin()
.,cbegin}
Definition at line 22046 of file json.hpp.
References cbegin().
|
inlinenoexcept |
returns an iterator to the first element
Returns an iterator to the first element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the Container requirements:
@liveexample{The following code shows an example for begin()
.,begin}
Definition at line 22036 of file json.hpp.
References rotate-tower::result.
Referenced by assert_invariant(), emplace(), front(), operator[](), and rend().
|
inlinestatic |
explicitly create a binary array (without subtype)
Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.
std::vector
. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.[in] | init | container containing bytes to use as binary type |
@complexity Linear in the size of init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
Definition at line 19179 of file json.hpp.
References basic_json(), nlohmann::detail::binary, init(), and altar_valkyrie::res.
|
inlinestatic |
explicitly create a binary array (with subtype)
Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.
std::vector
. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.[in] | init | container containing bytes to use as binary type |
[in] | subtype | subtype to use in MessagePack and BSON |
@complexity Linear in the size of init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
Definition at line 19216 of file json.hpp.
References basic_json(), nlohmann::detail::binary, init(), and altar_valkyrie::res.
|
inlinestatic |
explicitly create a binary array (without subtype)
Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.
std::vector
. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.[in] | init | container containing bytes to use as binary type |
@complexity Linear in the size of init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
Definition at line 19226 of file json.hpp.
References basic_json(), nlohmann::detail::binary, init(), and altar_valkyrie::res.
|
inlinestatic |
explicitly create a binary array (with subtype)
Creates a JSON binary array value from a given binary container. Binary values are part of various binary formats, such as CBOR, MessagePack, and BSON. This constructor is used to create a value for serialization to those formats.
std::vector
. Because JSON binary arrays are a non-standard extension it was decided that it would be best to prevent automatic initialization of a binary array type, for backwards compatibility and so it does not happen on accident.[in] | init | container containing bytes to use as binary type |
[in] | subtype | subtype to use in MessagePack and BSON |
@complexity Linear in the size of init.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes to any JSON value.
Definition at line 19236 of file json.hpp.
References basic_json(), nlohmann::detail::binary, init(), and altar_valkyrie::res.
|
inlinenoexcept |
returns a const iterator to the first element
Returns a const iterator to the first element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the Container requirements:
const_cast<const basic_json&>(*this).begin()
.@liveexample{The following code shows an example for cbegin()
.,cbegin}
Definition at line 22076 of file json.hpp.
References rotate-tower::result.
Referenced by begin(), crend(), front(), and update().
|
inlinenoexcept |
returns a const iterator to one past the last element
Returns a const iterator to one past the last element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the Container requirements:
const_cast<const basic_json&>(*this).end()
.@liveexample{The following code shows an example for cend()
.,cend}
Definition at line 22147 of file json.hpp.
References rotate-tower::result.
Referenced by back(), crbegin(), end(), find(), and update().
|
inlinenoexcept |
clears the contents
Clears the content of a JSON value and resets it to the default value as if basic_json(value_t) would have been called with the current value type from type():
Value type | initial value |
---|---|
null | null |
boolean | false |
string | "" |
number | 0 |
binary | An empty byte vector |
object | {} |
array | [] |
@liveexample{The example below shows the effect of clear()
to different JSON types.,clear}
@complexity Linear in the size of the JSON value.
@iterators All iterators, pointers and references related to this container are invalidated.
@exceptionsafety No-throw guarantee: this function never throws exceptions.
clear()
Definition at line 22728 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::discarded, m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, and nlohmann::detail::string.
|
inline |
check the existence of an element in a JSON object given a JSON pointer
Check whether the given JSON pointer ptr can be resolved in the current JSON value.
[in] | ptr | JSON pointer to check its existence. |
j.contains(ptr)
returns true, it is safe to call j[ptr]
.parse_error.106 | if an array index begins with '0' |
parse_error.109 | if an array index was not a number |
@complexity Logarithmic in the size of the JSON object.
@liveexample{The following code shows an example for contains()
.,contains_json_pointer}
|
inline |
check the existence of an element in a JSON object
Check whether an element exists in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, false is returned.
[in] | key | key value to check its existence. |
@complexity Logarithmic in the size of the JSON object.
@liveexample{The following code shows an example for contains()
.,contains}
Definition at line 21966 of file json.hpp.
References is_object(), and m_value.
Referenced by inja::Renderer::visit().
|
inline |
returns the number of occurrences of a key in a JSON object
Returns the number of elements with key key. If ObjectType is the default std::map
type, the return value will always be 0
(key was not found) or 1
(key was found).
0
when executed on a JSON type that is not an object.[in] | key | key value of the element to count |
0
.@complexity Logarithmic in the size of the JSON object.
@liveexample{The example shows how count()
is used.,count}
Definition at line 21933 of file json.hpp.
References is_object(), and m_value.
Referenced by set_parents().
|
inlinenoexcept |
returns a const reverse iterator to the last element
Returns a const iterator to the reverse-beginning; that is, the last element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the ReversibleContainer requirements:
const_cast<const basic_json&>(*this).rbegin()
.@liveexample{The following code shows an example for crbegin()
.,crbegin}
Definition at line 22251 of file json.hpp.
References cend().
Referenced by rbegin().
|
inlinestaticprivate |
helper for exception-safe object creation
Definition at line 18310 of file json.hpp.
References make_face_from_files::args, JSON_ASSERT, and altar_valkyrie::obj.
|
inlinenoexcept |
returns a const reverse iterator to one before the first
Returns a const reverse iterator to the reverse-end; that is, one before the first element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the ReversibleContainer requirements:
const_cast<const basic_json&>(*this).rend()
.@liveexample{The following code shows an example for crend()
.,crend}
Definition at line 22280 of file json.hpp.
References cbegin().
Referenced by rend().
|
inlineprivate |
Definition at line 18516 of file json.hpp.
References nlohmann::detail::array, array, nlohmann::detail::binary, binary, nlohmann::detail::boolean, nlohmann::detail::discarded, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, nlohmann::detail::string, and Floor::t.
Referenced by erase().
|
inlinestatic |
creates a diff as a JSON patch
Creates a JSON Patch so that value source can be changed into the value target by calling patch function.
true
: remove
, add
, and replace
operations are generated.[in] | source | JSON value to compare from |
[in] | target | JSON value to compare against |
[in] | path | helper value to create JSON pointers |
@complexity Linear in the lengths of source and target.
@liveexample{The following code shows how a JSON patch is created as a diff for two JSON values.,diff}
Definition at line 26097 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::discarded, nlohmann::detail::escape(), nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, object(), python_init::path, rotate-tower::result, nlohmann::detail::string, and nlohmann::to_string().
Referenced by fill_json().
|
inline |
serialization
Serialization function for JSON values. The function tries to mimic Python's json.dumps()
function, and currently supports its indent and ensure_ascii parameters.
[in] | indent | If indent is nonnegative, then array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. -1 (the default) selects the most compact representation. |
[in] | indent_char | The character to use for indentation if indent is greater than 0 . The default is (space). |
[in] | ensure_ascii | If ensure_ascii is true, all non-ASCII characters in the output are escaped with \uXXXX sequences, and the result consists of ASCII characters only. |
[in] | error_handler | how to react on decoding errors; there are three possible values: strict (throws and exception in case a decoding error occurs; default), replace (replace invalid UTF-8 sequences with U+FFFD), and ignore (ignore invalid UTF-8 sequences during serialization; all bytes are copied to the output unchanged). |
type_error.316 | if a string stored inside the JSON value is not UTF-8 encoded and error_handler is set to strict |
@complexity Linear.
@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
@liveexample{The following example shows the effect of different indent\, indent_char\, and ensure_ascii parameters to the result of the serialization.,dump}
Definition at line 19784 of file json.hpp.
References rotate-tower::result.
|
inline |
add an object to an object if key does not exist
Inserts a new element into a JSON object constructed in-place with the given args if there is no element with the key in the container. If the function is called on a JSON null value, an empty object is created before appending the value created from args.
[in] | args | arguments to forward to a constructor of basic_json |
Args | compatible types to create a basic_json object |
type_error.311 | when called on a type other than JSON object or null; example: "cannot use emplace() with number" |
@complexity Logarithmic in the size of the container, O(log(size()
)).
@liveexample{The example shows how emplace()
can be used to add elements to a JSON object. Note how the null
value was silently converted to a JSON object. Further note how no value is added if there was already one value stored with the same key.,emplace}
Definition at line 23050 of file json.hpp.
References make_face_from_files::args, assert_invariant(), begin(), nlohmann::detail::type_error::create(), is_null(), is_object(), JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, nlohmann::detail::object, altar_valkyrie::res, set_parent(), and type_name().
|
inline |
add an object to an array
Creates a JSON value from the passed parameters args to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending the value created from args.
[in] | args | arguments to forward to a constructor of basic_json |
Args | compatible types to create a basic_json object |
type_error.311 | when called on a type other than JSON array or null; example: "cannot use emplace_back() with number" |
@complexity Amortized constant.
@liveexample{The example shows how push_back()
can be used to add elements to a JSON array. Note how the null
value was silently converted to a JSON array.,emplace_back}
Definition at line 23000 of file json.hpp.
References make_face_from_files::args, nlohmann::detail::array, assert_invariant(), nlohmann::detail::type_error::create(), is_array(), is_null(), JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, set_parent(), and type_name().
Referenced by inja::Renderer::render_to().
|
inlinenoexcept |
checks whether the container is empty.
Checks if a JSON value has no elements (i.e. whether its size is 0
).
Value type | return value |
---|---|
null | true |
boolean | false |
string | false |
number | false |
binary | false |
object | result of function object_t::empty() |
array | result of function array_t::empty() |
@liveexample{The following code uses empty()
to check if a JSON object contains any elements.,empty}
@complexity Constant, as long as array_t and object_t satisfy the Container concept; that is, their empty()
functions have constant complexity.
@iterators No changes.
@exceptionsafety No-throw guarantee: this function never throws exceptions.
@requirement This function helps basic_json
satisfying the Container requirements:
Definition at line 22491 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::discarded, m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, and nlohmann::detail::string.
Referenced by inja::Renderer::visit().
|
inlinenoexcept |
returns a const iterator to one past the last element
Returns a const iterator to one past the last element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the Container requirements:
const_cast<const basic_json&>(*this).end()
.@liveexample{The following code shows an example for cend()
.,cend}
Definition at line 22117 of file json.hpp.
References cend().
|
inlinenoexcept |
returns an iterator to one past the last element
Returns an iterator to one past the last element.
@complexity Constant.
@requirement This function helps basic_json
satisfying the Container requirements:
@liveexample{The following code shows an example for end()
.,end}
Definition at line 22107 of file json.hpp.
References rotate-tower::result.
Referenced by assert_invariant(), back(), erase(), find(), rbegin(), and value().
|
inline |
remove element from a JSON array given an index
Removes element from a JSON array at the index idx.
[in] | idx | index of the element to remove |
type_error.307 | when called on a type other than JSON object; example: "cannot use erase() with null" |
out_of_range.401 | when idx >= size() ; example: "array index 17
is out of range" |
@complexity Linear in distance between idx and the end of the container.
@liveexample{The example shows the effect of erase()
.,erase__size_type}
Definition at line 21829 of file json.hpp.
References nlohmann::detail::type_error::create(), nlohmann::detail::out_of_range::create(), is_array(), JSON_HEDLEY_LIKELY, JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, size(), nlohmann::to_string(), and type_name().
|
inline |
remove element from a JSON object given a key
Removes elements from a JSON object with the key value key.
[in] | key | value of the elements to remove |
std::map
type, the return value will always be 0
(key was not found) or 1
(key was found).type_error.307 | when called on a type other than JSON object; example: "cannot use erase() with null" |
@complexity log(size()) + count(key)
@liveexample{The example shows the effect of erase()
.,erase__key_type}
Definition at line 21794 of file json.hpp.
References nlohmann::detail::type_error::create(), is_object(), JSON_HEDLEY_LIKELY, JSON_THROW, m_value, and type_name().
|
inline |
remove elements given an iterator range
Removes the element specified by the range [first; last)
. The iterator first does not need to be dereferenceable if first == last
: erasing an empty range is a no-op.
If called on a primitive type other than null
, the resulting JSON value will be null
.
[in] | first | iterator to the beginning of the range to remove |
[in] | last | iterator past the end of the range to remove |
end()
iterator is returned.IteratorType | an iterator or const_iterator |
end()
iterator.type_error.307 | if called on a null value; example: "cannot use
erase() with null" |
invalid_iterator.203 | if called on iterators which does not belong to the current JSON value; example: "iterators do not fit current value" |
invalid_iterator.204 | if called on a primitive type with invalid iterators (i.e., if first != begin() and last != end() ); example: "iterators out of range" |
@complexity The complexity depends on the type:
log(size()) + std::distance(first, last)
@liveexample{The example shows the result of erase()
for different JSON types.,erase__IteratorType_IteratorType}
Definition at line 21697 of file json.hpp.
References nlohmann::detail::array, assert_invariant(), nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), destroy(), nlohmann::detail::discarded, end(), is_binary(), is_string(), JSON_HEDLEY_LIKELY, JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, rotate-tower::result, nlohmann::detail::string, and type_name().
|
inline |
remove element given an iterator
Removes the element specified by iterator pos. The iterator pos must be valid and dereferenceable. Thus the end()
iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.
If called on a primitive type other than null
, the resulting JSON value will be null
.
[in] | pos | iterator to the element to remove |
end()
iterator is returned.IteratorType | an iterator or const_iterator |
end()
iterator.type_error.307 | if called on a null value; example: "cannot use
erase() with null" |
invalid_iterator.202 | if called on an iterator which does not belong to the current JSON value; example: "iterator does not fit current
value" |
invalid_iterator.205 | if called on a primitive type with invalid iterator (i.e., any iterator which is not begin() ); example: "iterator
out of range" |
@complexity The complexity depends on the type:
@liveexample{The example shows the result of erase()
for different JSON types.,erase__IteratorType}
Definition at line 21582 of file json.hpp.
References nlohmann::detail::array, assert_invariant(), nlohmann::detail::binary, nlohmann::detail::boolean, nlohmann::detail::invalid_iterator::create(), nlohmann::detail::type_error::create(), destroy(), nlohmann::detail::discarded, end(), is_binary(), is_string(), JSON_HEDLEY_UNLIKELY, JSON_THROW, m_value, nlohmann::detail::null, nlohmann::detail::number_float, nlohmann::detail::number_integer, nlohmann::detail::number_unsigned, nlohmann::detail::object, rotate-tower::result, nlohmann::detail::string, and type_name().
Referenced by main(), and merge_patch().
|
inline |
find an element in a JSON object
Finds an element in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, end() is returned.
[in] | key | key value of the element to search for. |
@complexity Logarithmic in the size of the JSON object.
@liveexample{The example shows how find()
is used.,find__key_type}
Definition at line 21882 of file json.hpp.
References end(), is_object(), m_value, and rotate-tower::result.
Referenced by value().
|
inline |
find an element in a JSON object
find an element in a JSON object Finds an element in a JSON object with key equivalent to key. If the element is not found or the JSON value is not an object, end() is returned.
[in] | key | key value of the element to search for. |
@complexity Logarithmic in the size of the JSON object.
@liveexample{The example shows how find()
is used.,find__key_type}
Definition at line 21899 of file json.hpp.
References cend(), is_object(), m_value, and rotate-tower::result.
|
inline |
return flattened JSON value
The function creates a JSON object whose keys are JSON pointers (see RFC 6901) and whose values are all primitive. The original JSON value can be restored using the unflatten() function.
null
and will not be reconstructed correctly by the unflatten() function.@complexity Linear in the size the JSON value.
@liveexample{The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.,flatten}
Definition at line 25693 of file json.hpp.
References nlohmann::json_pointer< BasicJsonType >::flatten(), nlohmann::detail::object, and rotate-tower::result.
|
inlinestatic |
Definition at line 25490 of file json.hpp.
References from_bson().
|
inlinestatic |
Definition at line 25499 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
Create a JSON value from an input in BSON format.
Deserializes a given input i to a JSON value using the BSON (Binary JSON) serialization format.
The library maps BSON record types to JSON value types as follows:
BSON type | BSON marker byte | JSON value type |
---|---|---|
double | 0x01 | number_float |
string | 0x02 | string |
document | 0x03 | object |
array | 0x04 | array |
binary | 0x05 | binary |
undefined | 0x06 | still unsupported |
ObjectId | 0x07 | still unsupported |
boolean | 0x08 | boolean |
UTC Date-Time | 0x09 | still unsupported |
null | 0x0A | null |
Regular Expr. | 0x0B | still unsupported |
DB Pointer | 0x0C | still unsupported |
JavaScript Code | 0x0D | still unsupported |
Symbol | 0x0E | still unsupported |
JavaScript Code | 0x0F | still unsupported |
int32 | 0x10 | number_integer |
Timestamp | 0x11 | still unsupported |
128-bit decimal float | 0x13 | still unsupported |
Max Key | 0x7F | still unsupported |
Min Key | 0xFF | still unsupported |
[in] | i | an input in BSON format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
false
, the return value will be value_t::discarded.parse_error.114 | if an unsupported BSON record type is encountered |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in BSON format to a JSON value.,from_bson}
Definition at line 25460 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
Referenced by from_bson().
|
inlinestatic |
Create a JSON value from an input in BSON format.
Deserializes a given input i to a JSON value using the BSON (Binary JSON) serialization format.
The library maps BSON record types to JSON value types as follows:
BSON type | BSON marker byte | JSON value type |
---|---|---|
double | 0x01 | number_float |
string | 0x02 | string |
document | 0x03 | object |
array | 0x04 | array |
binary | 0x05 | binary |
undefined | 0x06 | still unsupported |
ObjectId | 0x07 | still unsupported |
boolean | 0x08 | boolean |
UTC Date-Time | 0x09 | still unsupported |
null | 0x0A | null |
Regular Expr. | 0x0B | still unsupported |
DB Pointer | 0x0C | still unsupported |
JavaScript Code | 0x0D | still unsupported |
Symbol | 0x0E | still unsupported |
JavaScript Code | 0x0F | still unsupported |
int32 | 0x10 | number_integer |
Timestamp | 0x11 | still unsupported |
128-bit decimal float | 0x13 | still unsupported |
Max Key | 0x7F | still unsupported |
Min Key | 0xFF | still unsupported |
[in] | i | an input in BSON format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
false
, the return value will be value_t::discarded.parse_error.114 | if an unsupported BSON record type is encountered |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in BSON format to a JSON value.,from_bson}
Definition at line 25476 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
Definition at line 25117 of file json.hpp.
References from_cbor().
|
inlinestatic |
Definition at line 25128 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
create a JSON value from an input in CBOR format
Deserializes a given input i to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.
The library maps CBOR types to JSON value types as follows:
CBOR type | JSON value type | first byte |
---|---|---|
Integer | number_unsigned | 0x00..0x17 |
Unsigned integer | number_unsigned | 0x18 |
Unsigned integer | number_unsigned | 0x19 |
Unsigned integer | number_unsigned | 0x1A |
Unsigned integer | number_unsigned | 0x1B |
Negative integer | number_integer | 0x20..0x37 |
Negative integer | number_integer | 0x38 |
Negative integer | number_integer | 0x39 |
Negative integer | number_integer | 0x3A |
Negative integer | number_integer | 0x3B |
Byte string | binary | 0x40..0x57 |
Byte string | binary | 0x58 |
Byte string | binary | 0x59 |
Byte string | binary | 0x5A |
Byte string | binary | 0x5B |
UTF-8 string | string | 0x60..0x77 |
UTF-8 string | string | 0x78 |
UTF-8 string | string | 0x79 |
UTF-8 string | string | 0x7A |
UTF-8 string | string | 0x7B |
UTF-8 string | string | 0x7F |
array | array | 0x80..0x97 |
array | array | 0x98 |
array | array | 0x99 |
array | array | 0x9A |
array | array | 0x9B |
array | array | 0x9F |
map | object | 0xA0..0xB7 |
map | object | 0xB8 |
map | object | 0xB9 |
map | object | 0xBA |
map | object | 0xBB |
map | object | 0xBF |
False | false | 0xF4 |
True | true | 0xF5 |
Null | null | 0xF6 |
Half-Precision Float | number_float | 0xF9 |
Single-Precision Float | number_float | 0xFA |
Double-Precision Float | number_float | 0xFB |
[in] | i | an input in CBOR format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
[in] | tag_handler | how to treat CBOR tags (optional, error by default) |
false
, the return value will be value_t::discarded.parse_error.110 | if the given input ends prematurely or the end of file was not reached when strict was set to true |
parse_error.112 | if unsupported features from CBOR were used in the given input v or if the input is not valid CBOR |
parse_error.113 | if a string was expected as map key, but not found |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in CBOR format to a JSON value.,from_cbor}
Definition at line 25085 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
Referenced by from_cbor().
|
inlinestatic |
create a JSON value from an input in CBOR format
Deserializes a given input i to a JSON value using the CBOR (Concise Binary Object Representation) serialization format.
The library maps CBOR types to JSON value types as follows:
CBOR type | JSON value type | first byte |
---|---|---|
Integer | number_unsigned | 0x00..0x17 |
Unsigned integer | number_unsigned | 0x18 |
Unsigned integer | number_unsigned | 0x19 |
Unsigned integer | number_unsigned | 0x1A |
Unsigned integer | number_unsigned | 0x1B |
Negative integer | number_integer | 0x20..0x37 |
Negative integer | number_integer | 0x38 |
Negative integer | number_integer | 0x39 |
Negative integer | number_integer | 0x3A |
Negative integer | number_integer | 0x3B |
Byte string | binary | 0x40..0x57 |
Byte string | binary | 0x58 |
Byte string | binary | 0x59 |
Byte string | binary | 0x5A |
Byte string | binary | 0x5B |
UTF-8 string | string | 0x60..0x77 |
UTF-8 string | string | 0x78 |
UTF-8 string | string | 0x79 |
UTF-8 string | string | 0x7A |
UTF-8 string | string | 0x7B |
UTF-8 string | string | 0x7F |
array | array | 0x80..0x97 |
array | array | 0x98 |
array | array | 0x99 |
array | array | 0x9A |
array | array | 0x9B |
array | array | 0x9F |
map | object | 0xA0..0xB7 |
map | object | 0xB8 |
map | object | 0xB9 |
map | object | 0xBA |
map | object | 0xBB |
map | object | 0xBF |
False | false | 0xF4 |
True | true | 0xF5 |
Null | null | 0xF6 |
Half-Precision Float | number_float | 0xF9 |
Single-Precision Float | number_float | 0xFA |
Double-Precision Float | number_float | 0xFB |
[in] | i | an input in CBOR format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
[in] | tag_handler | how to treat CBOR tags (optional, error by default) |
false
, the return value will be value_t::discarded.parse_error.110 | if the given input ends prematurely or the end of file was not reached when strict was set to true |
parse_error.112 | if unsupported features from CBOR were used in the given input v or if the input is not valid CBOR |
parse_error.113 | if a string was expected as map key, but not found |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in CBOR format to a JSON value.,from_cbor}
Definition at line 25102 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
Definition at line 25260 of file json.hpp.
References from_msgpack().
|
inlinestatic |
Definition at line 25269 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
create a JSON value from an input in MessagePack format
Deserializes a given input i to a JSON value using the MessagePack serialization format.
The library maps MessagePack types to JSON value types as follows:
MessagePack type | JSON value type | first byte |
---|---|---|
positive fixint | number_unsigned | 0x00..0x7F |
fixmap | object | 0x80..0x8F |
fixarray | array | 0x90..0x9F |
fixstr | string | 0xA0..0xBF |
nil | null | 0xC0 |
false | false | 0xC2 |
true | true | 0xC3 |
float 32 | number_float | 0xCA |
float 64 | number_float | 0xCB |
uint 8 | number_unsigned | 0xCC |
uint 16 | number_unsigned | 0xCD |
uint 32 | number_unsigned | 0xCE |
uint 64 | number_unsigned | 0xCF |
int 8 | number_integer | 0xD0 |
int 16 | number_integer | 0xD1 |
int 32 | number_integer | 0xD2 |
int 64 | number_integer | 0xD3 |
str 8 | string | 0xD9 |
str 16 | string | 0xDA |
str 32 | string | 0xDB |
array 16 | array | 0xDC |
array 32 | array | 0xDD |
map 16 | object | 0xDE |
map 32 | object | 0xDF |
bin 8 | binary | 0xC4 |
bin 16 | binary | 0xC5 |
bin 32 | binary | 0xC6 |
ext 8 | binary | 0xC7 |
ext 16 | binary | 0xC8 |
ext 32 | binary | 0xC9 |
fixext 1 | binary | 0xD4 |
fixext 2 | binary | 0xD5 |
fixext 4 | binary | 0xD6 |
fixext 8 | binary | 0xD7 |
fixext 16 | binary | 0xD8 |
negative fixint | number_integer | 0xE0-0xFF |
[in] | i | an input in MessagePack format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
false
, the return value will be value_t::discarded.parse_error.110 | if the given input ends prematurely or the end of file was not reached when strict was set to true |
parse_error.112 | if unsupported features from MessagePack were used in the given input i or if the input is not valid MessagePack |
parse_error.113 | if a string was expected as map key, but not found |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in MessagePack format to a JSON value.,from_msgpack}
Definition at line 25229 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
Referenced by from_msgpack().
|
inlinestatic |
create a JSON value from an input in MessagePack format
Deserializes a given input i to a JSON value using the MessagePack serialization format.
The library maps MessagePack types to JSON value types as follows:
MessagePack type | JSON value type | first byte |
---|---|---|
positive fixint | number_unsigned | 0x00..0x7F |
fixmap | object | 0x80..0x8F |
fixarray | array | 0x90..0x9F |
fixstr | string | 0xA0..0xBF |
nil | null | 0xC0 |
false | false | 0xC2 |
true | true | 0xC3 |
float 32 | number_float | 0xCA |
float 64 | number_float | 0xCB |
uint 8 | number_unsigned | 0xCC |
uint 16 | number_unsigned | 0xCD |
uint 32 | number_unsigned | 0xCE |
uint 64 | number_unsigned | 0xCF |
int 8 | number_integer | 0xD0 |
int 16 | number_integer | 0xD1 |
int 32 | number_integer | 0xD2 |
int 64 | number_integer | 0xD3 |
str 8 | string | 0xD9 |
str 16 | string | 0xDA |
str 32 | string | 0xDB |
array 16 | array | 0xDC |
array 32 | array | 0xDD |
map 16 | object | 0xDE |
map 32 | object | 0xDF |
bin 8 | binary | 0xC4 |
bin 16 | binary | 0xC5 |
bin 32 | binary | 0xC6 |
ext 8 | binary | 0xC7 |
ext 16 | binary | 0xC8 |
ext 32 | binary | 0xC9 |
fixext 1 | binary | 0xD4 |
fixext 2 | binary | 0xD5 |
fixext 4 | binary | 0xD6 |
fixext 8 | binary | 0xD7 |
fixext 16 | binary | 0xD8 |
negative fixint | number_integer | 0xE0-0xFF |
[in] | i | an input in MessagePack format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
false
, the return value will be value_t::discarded.parse_error.110 | if the given input ends prematurely or the end of file was not reached when strict was set to true |
parse_error.112 | if unsupported features from MessagePack were used in the given input i or if the input is not valid MessagePack |
parse_error.113 | if a string was expected as map key, but not found |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in MessagePack format to a JSON value.,from_msgpack}
Definition at line 25245 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
Definition at line 25376 of file json.hpp.
References from_ubjson().
|
inlinestatic |
Definition at line 25385 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inlinestatic |
create a JSON value from an input in UBJSON format
Deserializes a given input i to a JSON value using the UBJSON (Universal Binary JSON) serialization format.
The library maps UBJSON types to JSON value types as follows:
UBJSON type | JSON value type | marker |
---|---|---|
no-op | no value, next value is read | N |
null | null | Z |
false | false | F |
true | true | T |
float32 | number_float | d |
float64 | number_float | D |
uint8 | number_unsigned | U |
int8 | number_integer | i |
int16 | number_integer | I |
int32 | number_integer | l |
int64 | number_integer | L |
high-precision number | number_integer, number_unsigned, or number_float - depends on number string | 'H' |
string | string | S |
char | string | C |
array | array (optimized values are supported) | [ |
object | object (optimized values are supported) | { |
[in] | i | an input in UBJSON format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
false
, the return value will be value_t::discarded.parse_error.110 | if the given input ends prematurely or the end of file was not reached when strict was set to true |
parse_error.112 | if a parse error occurs |
parse_error.113 | if a string could not be parsed successfully |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in UBJSON format to a JSON value.,from_ubjson}
Definition at line 25346 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
Referenced by from_ubjson().
|
inlinestatic |
create a JSON value from an input in UBJSON format
Deserializes a given input i to a JSON value using the UBJSON (Universal Binary JSON) serialization format.
The library maps UBJSON types to JSON value types as follows:
UBJSON type | JSON value type | marker |
---|---|---|
no-op | no value, next value is read | N |
null | null | Z |
false | false | F |
true | true | T |
float32 | number_float | d |
float64 | number_float | D |
uint8 | number_unsigned | U |
int8 | number_integer | i |
int16 | number_integer | I |
int32 | number_integer | l |
int64 | number_integer | L |
high-precision number | number_integer, number_unsigned, or number_float - depends on number string | 'H' |
string | string | S |
char | string | C |
array | array (optimized values are supported) | [ |
object | object (optimized values are supported) | { |
[in] | i | an input in UBJSON format convertible to an input adapter |
[in] | strict | whether to expect the input to be consumed until EOF (true by default) |
[in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default) |
false
, the return value will be value_t::discarded.parse_error.110 | if the given input ends prematurely or the end of file was not reached when strict was set to true |
parse_error.112 | if a parse error occurs |
parse_error.113 | if a string could not be parsed successfully |
@complexity Linear in the size of the input i.
@liveexample{The example shows the deserialization of a byte vector in UBJSON format to a JSON value.,from_ubjson}
Definition at line 25362 of file json.hpp.
References basic_json(), nlohmann::detail::discarded, nlohmann::detail::input_adapter(), altar_valkyrie::res, rotate-tower::result, and nlohmann::detail::binary_reader< BasicJsonType, InputAdapterType, SAX >::sax_parse().
|
inline |
access the first element
Returns a reference to the first element in the container. For a JSON container c
, the expression c.front()
is equivalent to *c.begin()
.
@complexity Constant.
null
(would throw std::out_of_range
) or an empty array or object (undefined behavior, guarded by assertions). invalid_iterator.214 | when called on null value |
@liveexample{The following code shows an example for front()
.,front}
Definition at line 21471 of file json.hpp.
References begin().
|
inline |
access the first element
Returns a reference to the first element in the container. For a JSON container c
, the expression c.front()
is equivalent to *c.begin()
.
@complexity Constant.
null
(would throw std::out_of_range
) or an empty array or object (undefined behavior, guarded by assertions). invalid_iterator.214 | when called on null value |
@liveexample{The following code shows an example for front()
.,front}
Definition at line 21479 of file json.hpp.
References cbegin().
|
inlinenoexcept |
get a (pointer) value (explicit)
Performs explicit type conversion between the JSON value and a compatible value if required.
from_json()
method.ValueTypeCV | the provided value type |
ValueType | the returned value type |
ValueType | if necessary |
what | json_serializer<ValueType> from_json() method throws if conversion is required |
|
inlinenoexcept |
get a pointer value (explicit)
Explicit pointer access to the internally stored JSON value. No copies are made.
PointerType | pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. |
nullptr
otherwise@complexity Constant.
@liveexample{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr
is returned if the value and the requested pointer type does not match.,get__PointerType}
|
inlinestatic |
|
inline |
type_error.302 | if the value is not binary |
Definition at line 20794 of file json.hpp.
References nlohmann::detail::type_error::create(), is_binary(), JSON_THROW, and type_name().
|
inline |
type_error.302 | if the value is not binary |
Definition at line 20805 of file json.hpp.
References nlohmann::detail::type_error::create(), is_binary(), JSON_THROW, and type_name().
get a boolean (explicit)
Definition at line 20208 of file json.hpp.
References nlohmann::detail::type_error::create(), is_boolean(), JSON_HEDLEY_LIKELY, JSON_THROW, m_value, and type_name().
|
inlineprivatenoexcept |
get a value (explicit)
Explicit type conversion between the JSON value and a compatible value which is CopyConstructible and DefaultConstructible. The value is converted by calling the json_serializer<ValueType> from_json()
method.
The function is equivalent to executing
This overloads is chosen if:
from_json()
method of the form void from_json(const basic_json&, ValueType&)
, andfrom_json()
method of the form ValueType from_json(const basic_json&)
ValueType | the returned value type |
what | json_serializer<ValueType> from_json() method throws |
@liveexample{The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers\, (2) A JSON array can be converted to a standard std::vector<short>
\, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string\, json>
.,get__ValueType_const}
Definition at line 20435 of file json.hpp.
References nlohmann::detail::from_json().
|
inlineprivatenoexcept |
get a value (explicit); special case
Explicit type conversion between the JSON value and a compatible value which is not CopyConstructible and not DefaultConstructible. The value is converted by calling the json_serializer<ValueType> from_json()
method.
The function is equivalent to executing
This overloads is chosen if:
from_json()
method of the form ValueType from_json(const basic_json&)
from_json()
, this one is chosen.ValueType | the returned value type |
what | json_serializer<ValueType> from_json() method throws |
Definition at line 20477 of file json.hpp.
References nlohmann::detail::from_json().
|
inlineprivate |
get special-case overload
This overloads converts the current basic_json in a different basic_json type
BasicJsonType | == basic_json |
@complexity Depending on the implementation of the called from_json()
method.
|
inlineprivate |
get special-case overload
This overloads avoids a lot of template boilerplate, it can be seen as the identity method
BasicJsonType | == basic_json |
@complexity Constant.
return nlohmann::basic_json::get_impl | ( | detail::priority_tag< 4 > {} | ) |
|
inlineconstexprprivatenoexcept |
get a pointer value (explicit)
get a pointer value (explicit) Explicit pointer access to the internally stored JSON value. No copies are made.
PointerType | pointer type; must be a pointer to array_t, object_t, string_t, boolean_t, number_integer_t, number_unsigned_t, or number_float_t. |
nullptr
otherwise@complexity Constant.
@liveexample{The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr
is returned if the value and the requested pointer type does not match.,get__PointerType}
get a pointer to the value (array)
Definition at line 20231 of file json.hpp.
References is_array(), and m_value.
get a pointer to the value (binary)
Definition at line 20303 of file json.hpp.
References is_binary(), and m_value.
get a pointer to the value (boolean)
Definition at line 20255 of file json.hpp.
References is_boolean(), and m_value.