JSON for Modern C++ 3.9.1

__pad3__
accept
accept
accept
allocator_type
array
array_t
at
at
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
binary
binary
binary
binary
binary_t
boolean_t
cbegin
cbor_tag_handler_t
cend
clear
const_iterator
const_pointer
const_reference
const_reverse_iterator
contains
contains
count
crbegin
crend
detail::external_constructor
diff
difference_type
dump
emplace
emplace_back
empty
end
end
erase
erase
erase
erase
error_handler_t
exception
find
find
flatten
from_bson
from_bson
from_bson
from_bson
from_cbor
from_cbor
from_cbor
from_cbor
from_msgpack
from_msgpack
from_msgpack
from_msgpack
from_ubjson
from_ubjson
from_ubjson
from_ubjson
front
front
get
get
get
get
get
get
get_allocator
get_binary
get_binary
get_ptr
get_ptr
get_ref
get_ref
get_to
get_to
get_to
initializer_list_t
input_format_t
insert
insert
insert
insert
insert
insert
insert_iterator
invalid_iterator
is_array
is_binary
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_number_unsigned
is_object
is_primitive
is_string
is_structured
items
items
iterator
iterator_wrapper
iterator_wrapper
json_pointer
json_sax_t
json_serializer
m_value
max_size
merge_patch
meta
number_float_t
number_integer_t
number_unsigned_t
object
object_comparator_t
object_t
operator value_t
operator ValueType
operator!=
operator!=
operator!=
operator+=
operator+=
operator+=
operator+=
operator<
operator<
operator<
operator<<
operator<<
operator<=
operator<=
operator<=
operator=
operator==
operator==
operator==
operator>
operator>
operator>
operator>=
operator>=
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
other_error
out_of_range
parse
parse
parse
parse_error
parse_event_t
parser_callback_t
patch
pointer
push_back
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
sax_parse
sax_parse
sax_parse
size
size_type
string_t
swap
swap
swap
swap
swap
swap
swap
to_bson
to_bson
to_bson
to_cbor
to_cbor
to_cbor
to_msgpack
to_msgpack
to_msgpack
to_ubjson
to_ubjson
to_ubjson
type
type_error
type_name
unflatten
update
update
value
value
value
value
value_t
value_type
~basic_json
| ## ◆ type_error template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::type_error = detail::type_error
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)
  Example The following code shows how a `type_error` exception can be caught. 1 #include <iostream> 2 #include <nlohmann/json.hpp> 3 4 using json = nlohmann::json; 5 6 int main() 7 { 8 try 9 { 10 // calling push_back() on a string value 11 json j = "string"; 12 j.push_back("another string"); 13 } 14 catch (json::type_error& e) 15 { 16 // output exception information 17 std::cout << "message: " << e.what() << '\n' 18 << "exception id: " << e.id << std::endl; 19 } 20 } Output (play with this example online):
      message: [json.exception.type_error.308] cannot use push_back() with string
      exception id: 308
  The example code above can be translated with
      g++ -std=c++11 -Isingle_include doc/examples/type_error.cpp -o type_error
See also - exception for the base class of the library exceptions - parse_error for exceptions indicating a parse error - invalid_iterator for exceptions indicating errors with iterators - out_of_range for exceptions indicating access out of the defined range - other_error for exceptions indicating other library errors Since version 3.0.0 Definition at line 16766 of file json.hpp.

nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2940
nlohmann::basic_json::type_error
detail::type_error type_error
exception indicating executing a member function with a wrong type
Definition: json.hpp:16766