JSON for Modern C++
3.0
|
JSON. More...
#include <json.hpp>
Classes | |
class | const_iterator |
a const random access iterator for the basic_json class More... | |
class | const_reverse_iterator |
a const reverse random access iterator for the basic_json class More... | |
union | internal_iterator |
an iterator value More... | |
class | iterator |
a random access iterator for the basic_json class More... | |
union | json_value |
a JSON value More... | |
class | lexer |
lexical analysis More... | |
class | parser |
syntax analysis More... | |
class | reverse_iterator |
a reverse random access iterator for the basic_json class More... | |
Public Types | |
enum | value_t : uint8_t { value_t::null, value_t::object, value_t::array, value_t::string, value_t::boolean, value_t::number_integer, value_t::number_float } |
JSON value type enumeration. More... | |
using | value_type = basic_json |
the type of elements in a basic_json container More... | |
using | reference = basic_json & |
the type of an element reference More... | |
using | const_reference = const basic_json & |
the type of an element const reference More... | |
using | difference_type = std::ptrdiff_t |
a type to represent differences between iterators More... | |
using | size_type = std::size_t |
a type to represent container sizes More... | |
using | allocator_type = Allocator< basic_json > |
the allocator type More... | |
using | pointer = basic_json * |
the type of an element pointer More... | |
using | const_pointer = const basic_json * |
the type of an element const pointer More... | |
using | iterator = basic_json::iterator |
an iterator for a basic_json container More... | |
using | const_iterator = basic_json::const_iterator |
a const iterator for a basic_json container More... | |
using | reverse_iterator = basic_json::reverse_iterator |
a reverse iterator for a basic_json container More... | |
using | const_reverse_iterator = basic_json::const_reverse_iterator |
a const reverse iterator for a basic_json container More... | |
using | object_t = ObjectType< StringType, basic_json > |
a type for an object More... | |
using | array_t = ArrayType< basic_json > |
a type for an array More... | |
using | string_t = StringType |
a type for a string More... | |
using | boolean_t = BooleanType |
a type for a boolean More... | |
using | number_integer_t = NumberIntegerType |
a type for a number (integer) More... | |
using | number_float_t = NumberFloatType |
a type for a number (floating-point) More... | |
using | list_init_t = std::initializer_list< basic_json > |
a type for list initialization More... | |
Public Member Functions | |
allocator_type | get_allocator () const |
returns the allocator associated with the container More... | |
basic_json (const value_t value) | |
create an empty value with a given type More... | |
basic_json () noexcept=default | |
create a null object (implicitly) More... | |
basic_json (std::nullptr_t) noexcept | |
create a null object (explicitly) More... | |
basic_json (const object_t &value) | |
create an object (explicit) More... | |
template<class V , typename std::enable_if< std::is_constructible< typename object_t::key_type, typename V::key_type >::value andstd::is_constructible< basic_json, typename V::mapped_type >::value, int >::type = 0> | |
basic_json (const V &value) | |
create an object (implicit) More... | |
basic_json (const array_t &value) | |
create an array (explicit) More... | |
template<class V , typename std::enable_if< not std::is_same< V, basic_json::iterator >::value andnot std::is_same< V, basic_json::const_iterator >::value andnot std::is_same< V, basic_json::reverse_iterator >::value andnot std::is_same< V, basic_json::const_reverse_iterator >::value andnot std::is_same< V, typename array_t::iterator >::value andnot std::is_same< V, typename array_t::const_iterator >::value andstd::is_constructible< basic_json, typename V::value_type >::value, int >::type = 0> | |
basic_json (const V &value) | |
create an array (implicit) More... | |
basic_json (const string_t &value) | |
create a string (explicit) More... | |
basic_json (const typename string_t::value_type *value) | |
create a string (explicit) More... | |
template<class V , typename std::enable_if< std::is_constructible< string_t, V >::value, int >::type = 0> | |
basic_json (const V &value) | |
create a string (implicit) More... | |
basic_json (boolean_t value) | |
create a boolean (explicit) More... | |
basic_json (const number_integer_t &value) | |
create an integer number (explicit) More... | |
template<typename T , typename std::enable_if< std::is_constructible< number_integer_t, T >::value andstd::numeric_limits< T >::is_integer, T >::type = 0> | |
basic_json (const T value) noexcept | |
create an integer number (implicit) More... | |
basic_json (const number_float_t &value) | |
create a floating-point number (explicit) More... | |
template<typename T , typename = typename std::enable_if< std::is_constructible<number_float_t, T>::value and std::is_floating_point<T>::value>::type> | |
basic_json (const T value) noexcept | |
create a floating-point number (implicit) More... | |
basic_json (list_init_t l, bool type_deduction=true, value_t manual_type=value_t::array) | |
create a container (array or object) from an initializer list More... | |
basic_json (const basic_json &other) | |
copy constructor More... | |
basic_json (basic_json &&other) noexcept | |
move constructor More... | |
reference & | operator= (basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value andstd::is_nothrow_move_assignable< value_t >::value andstd::is_nothrow_move_constructible< json_value >::value andstd::is_nothrow_move_assignable< json_value >::value) |
copy assignment More... | |
~basic_json () noexcept | |
destructor More... | |
string_t | dump (const int indent=-1) const noexcept |
serialization More... | |
value_t | type () const noexcept |
return the type of the object (explicit) More... | |
bool | is_null () const noexcept |
bool | is_boolean () const noexcept |
bool | is_number () const noexcept |
bool | is_object () const noexcept |
bool | is_array () const noexcept |
bool | is_string () const noexcept |
operator value_t () const noexcept | |
return the type of the object (implicit) More... | |
template<typename T > | |
T | get () const |
get a value (explicit) More... | |
template<typename T > | |
operator T () const | |
get a value (implicit) More... | |
reference | at (size_type pos) |
access specified element with bounds checking More... | |
const_reference | at (size_type pos) const |
access specified element with bounds checking More... | |
reference | operator[] (size_type pos) |
access specified element More... | |
const_reference | operator[] (size_type pos) const |
access specified element More... | |
reference | at (const typename object_t::key_type &key) |
access specified element with bounds checking More... | |
const_reference | at (const typename object_t::key_type &key) const |
access specified element with bounds checking More... | |
reference | operator[] (const typename object_t::key_type &key) |
access specified element More... | |
const_reference | operator[] (const typename object_t::key_type &key) const |
access specified element More... | |
template<typename T , size_t n> | |
reference | operator[] (const T(&key)[n]) |
access specified element (needed for clang) More... | |
template<typename T , size_t n> | |
const_reference | operator[] (const T(&key)[n]) const |
access specified element (needed for clang) More... | |
size_type | erase (const typename object_t::key_type &key) |
remove element from an object given a key More... | |
void | erase (const size_type pos) |
remove element from an array given an index More... | |
iterator | find (typename object_t::key_type key) |
find an element in an object More... | |
const_iterator | find (typename object_t::key_type key) const |
find an element in an object More... | |
size_type | count (typename object_t::key_type key) const |
returns the number of occurrences of a key in an object More... | |
iterator | begin () noexcept |
returns an iterator to the first element More... | |
const_iterator | begin () const noexcept |
returns a const iterator to the first element More... | |
const_iterator | cbegin () const noexcept |
returns a const iterator to the first element More... | |
iterator | end () noexcept |
returns an iterator to one past the last element More... | |
const_iterator | end () const noexcept |
returns a const iterator to one past the last element More... | |
const_iterator | cend () const noexcept |
returns a const iterator to one past the last element More... | |
reverse_iterator | rbegin () noexcept |
returns a reverse iterator to the first element More... | |
const_reverse_iterator | rbegin () const noexcept |
returns a const reverse iterator to the first element More... | |
reverse_iterator | rend () noexcept |
returns a reverse iterator to one past the last element More... | |
const_reverse_iterator | rend () const noexcept |
returns a const reverse iterator to one past the last element More... | |
const_reverse_iterator | crbegin () const noexcept |
returns a const reverse iterator to the first element More... | |
const_reverse_iterator | crend () const noexcept |
returns a const reverse iterator to one past the last element More... | |
bool | empty () const noexcept |
checks whether the container is empty More... | |
size_type | size () const noexcept |
returns the number of elements More... | |
size_type | max_size () const noexcept |
returns the maximum possible number of elements More... | |
void | clear () noexcept |
clears the contents More... | |
void | push_back (basic_json &&value) |
add an object to an array More... | |
reference | operator+= (basic_json &&value) |
add an object to an array More... | |
void | push_back (const basic_json &value) |
add an object to an array More... | |
reference | operator+= (const basic_json &value) |
add an object to an array More... | |
void | push_back (const typename object_t::value_type &value) |
add an object to an object More... | |
reference | operator+= (const typename object_t::value_type &value) |
add an object to an object More... | |
void | swap (reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value andstd::is_nothrow_move_assignable< value_t >::value andstd::is_nothrow_move_constructible< json_value >::value andstd::is_nothrow_move_assignable< json_value >::value) |
exchanges the values More... | |
void | swap (array_t &other) |
swaps the contents More... | |
void | swap (object_t &other) |
swaps the contents More... | |
void | swap (string_t &other) |
swaps the contents More... | |
Static Public Member Functions | |
static basic_json | array (list_init_t l=list_init_t()) |
explicitly create an array from an initializer list More... | |
static basic_json | object (list_init_t l=list_init_t()) |
explicitly create an object from an initializer list More... | |
static basic_json | parse (const string_t &s) |
deserialize from string More... | |
static basic_json | parse (std::istream &i) |
deserialize from stream More... | |
Private Member Functions | |
template<class T , typename std::enable_if< std::is_convertible< typename object_t::key_type, typename T::key_type >::value andstd::is_convertible< basic_json, typename T::mapped_type >::value, int >::type = 0> | |
T | get_impl (T *) const |
get an object (explicit) More... | |
object_t | get_impl (object_t *) const |
get an object (explicit) More... | |
template<class T , typename std::enable_if< std::is_convertible< basic_json, typename T::value_type >::value andnot std::is_same< basic_json, typename T::value_type >::value andnot std::is_arithmetic< T >::value andnot std::is_convertible< std::string, T >::value andnot has_mapped_type< T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get an array (explicit) More... | |
template<class T , typename std::enable_if< std::is_convertible< basic_json, T >::value andnot std::is_same< basic_json, T >::value, int >::type = 0> | |
std::vector< T > | get_impl (std::vector< T > *) const |
get an array (explicit) More... | |
template<class T , typename std::enable_if< std::is_same< basic_json, typename T::value_type >::value andnot has_mapped_type< T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get an array (explicit) More... | |
array_t | get_impl (array_t *) const |
template<typename T , typename std::enable_if< std::is_convertible< string_t, T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get a string (explicit) More... | |
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value, int >::type = 0> | |
T | get_impl (T *) const |
get a number (explicit) More... | |
boolean_t | get_impl (boolean_t *) const |
get a boolean (explicit) More... | |
string_t | type_name () const noexcept |
return the type as string More... | |
string_t | dump (const bool prettyPrint, const unsigned int indentStep, const unsigned int currentIndent=0) const noexcept |
internal implementation of the serialization function More... | |
Static Private Member Functions | |
static string_t | escape_string (const string_t &s) noexcept |
escape a string More... | |
template<typename T > | |
static bool | approx (const T a, const T b) |
"equality" comparison for floating point numbers More... | |
Private Attributes | |
value_t | m_type = value_t::null |
the type of the current element More... | |
bool | m_final = false |
whether the type of JSON object may change later More... | |
json_value | m_value = {} |
the value of the current element More... | |
Friends | |
bool | operator< (const value_t lhs, const value_t rhs) |
comparison operator for JSON value types More... | |
bool | operator== (const_reference lhs, const_reference rhs) noexcept |
comparison: equal More... | |
bool | operator!= (const_reference lhs, const_reference rhs) noexcept |
comparison: not equal More... | |
bool | operator< (const_reference lhs, const_reference rhs) noexcept |
comparison: less than More... | |
bool | operator<= (const_reference lhs, const_reference rhs) noexcept |
comparison: less than or equal More... | |
bool | operator> (const_reference lhs, const_reference rhs) noexcept |
comparison: greater than More... | |
bool | operator>= (const_reference lhs, const_reference rhs) noexcept |
comparison: greater than or equal More... | |
std::ostream & | operator<< (std::ostream &o, const basic_json &j) |
serialize to stream More... | |
std::ostream & | operator>> (const basic_json &j, std::ostream &o) |
serialize to stream More... | |
std::istream & | operator>> (std::istream &i, basic_json &j) |
deserialize from stream More... | |
std::istream & | operator<< (basic_json &j, std::istream &i) |
deserialize from stream More... | |
ObjectType | type for JSON objects (std::map by default) |
ArrayType | type for JSON arrays (std::vector by default) |
StringType | type for JSON strings and object keys (std::string by default) |
BooleanType | type for JSON booleans (bool by default) |
NumberIntegerType | type for JSON integer numbers (int64_t by default) |
NumberFloatType | type for JSON floating-point numbers (double by default) |
Allocator | type of the allocator to use (std::allocator by default) |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::allocator_type = Allocator<basic_json> |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::array_t = ArrayType<basic_json> |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::boolean_t = BooleanType |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::const_pointer = const basic_json* |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::list_init_t = std::initializer_list<basic_json> |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::number_float_t = NumberFloatType |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::number_integer_t = NumberIntegerType |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::object_t = ObjectType<StringType, basic_json> |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::pointer = basic_json* |
using nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::string_t = StringType |
|
strong |
Definition at line 241 of file json.hpp.
|
inline |
value | the type to create an value of |
std::bad_alloc | if allocation for object, array, or string fails. |
Definition at line 344 of file json.hpp.
|
inlinenoexcept |
|
inline |
Definition at line 410 of file json.hpp.
|
inline |
Definition at line 424 of file json.hpp.
|
inline |
Definition at line 435 of file json.hpp.
|
inline |
Definition at line 454 of file json.hpp.
|
inline |
Definition at line 465 of file json.hpp.
|
inline |
Definition at line 474 of file json.hpp.
|
inline |
|
inline |
Definition at line 492 of file json.hpp.
|
inline |
Definition at line 497 of file json.hpp.
|
inlinenoexcept |
Definition at line 507 of file json.hpp.
|
inline |
Definition at line 512 of file json.hpp.
|
inlinenoexcept |
Definition at line 522 of file json.hpp.
|
inline |
Definition at line 527 of file json.hpp.
|
inlinenoexcept |
Definition at line 668 of file json.hpp.
|
inlinestaticprivate |
|
inlinestatic |
Definition at line 590 of file json.hpp.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[]().
|
inline |
Definition at line 1037 of file json.hpp.
|
inline |
Definition at line 1049 of file json.hpp.
|
inline |
Definition at line 1099 of file json.hpp.
|
inline |
Definition at line 1111 of file json.hpp.
|
inlinenoexcept |
Definition at line 1481 of file json.hpp.
|
inline |
Definition at line 1246 of file json.hpp.
|
inlinenoexcept |
Serialization function for JSON objects. The function tries to mimick Python's json.dumps()
function, and currently supports its indent
parameter.
indent | sif 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 |
Definition at line 756 of file json.hpp.
Referenced by std::hash< nlohmann::json >::operator()().
|
inlineprivatenoexcept |
This function is called by the public member function dump and organizes the serializaion internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively. Note that
prettyPrint | whether the output shall be pretty-printed |
indentStep | the indent level |
currentIndent | the current indent level (only used internally) |
Definition at line 2066 of file json.hpp.
|
inline |
Definition at line 1191 of file json.hpp.
|
inline |
Definition at line 1203 of file json.hpp.
|
inlinestaticprivatenoexcept |
Escape a string by replacing certain special characters by a sequence of an escape character (backslash) and another character and other control characters by a sequence of "\u" followed by a four-digit hex representation.
s | the string to escape |
Definition at line 1966 of file json.hpp.
|
inline |
Definition at line 1220 of file json.hpp.
|
inline |
Definition at line 1233 of file json.hpp.
|
inline |
Definition at line 1019 of file json.hpp.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::get_impl().
|
inline |
Definition at line 179 of file json.hpp.
|
inlineprivate |
Definition at line 827 of file json.hpp.
|
inlineprivate |
Definition at line 843 of file json.hpp.
|
inlineprivate |
Definition at line 867 of file json.hpp.
|
inlineprivate |
Definition at line 897 of file json.hpp.
|
inlineprivate |
Definition at line 925 of file json.hpp.
|
inlineprivate |
Definition at line 940 of file json.hpp.
|
inlineprivate |
Definition at line 960 of file json.hpp.
|
inlineprivate |
Definition at line 980 of file json.hpp.
|
inlineprivate |
Definition at line 1000 of file json.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestatic |
Definition at line 596 of file json.hpp.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::operator[]().
|
inline |
|
inlinenoexcept |
|
inline |
Definition at line 1553 of file json.hpp.
References nlohmann::has_mapped_type< T >::value.
|
inline |
Definition at line 1582 of file json.hpp.
|
inline |
Definition at line 1611 of file json.hpp.
|
inline |
Definition at line 1061 of file json.hpp.
|
inline |
Definition at line 1087 of file json.hpp.
|
inline |
Definition at line 1123 of file json.hpp.
|
inline |
Definition at line 1144 of file json.hpp.
|
inline |
Definition at line 1157 of file json.hpp.
|
inline |
Definition at line 1179 of file json.hpp.
|
inlinestatic |
Definition at line 1887 of file json.hpp.
Referenced by operator""_json().
|
inlinestatic |
|
inline |
Definition at line 1529 of file json.hpp.
References nlohmann::has_mapped_type< T >::value.
|
inline |
Definition at line 1560 of file json.hpp.
|
inline |
Definition at line 1589 of file json.hpp.
|
inline |
Definition at line 1633 of file json.hpp.
References std::swap().
|
inline |
Definition at line 1646 of file json.hpp.
References std::swap().
|
inline |
Definition at line 1659 of file json.hpp.
References std::swap().
|
inlinenoexcept |
|
inlineprivatenoexcept |
|
friend |
Returns an ordering that is similar to Python:
Definition at line 259 of file json.hpp.
|
friend |
Definition at line 1763 of file json.hpp.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
|
private |
|
private |
Definition at line 2203 of file json.hpp.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, Allocator >::basic_json().