libfly
6.2.2
C++20 utility library for Linux, macOS, and Windows
|
#include <json.hpp>
Public Types | |
using | value_type = Json |
using | size_type = std::size_t |
using | difference_type = std::ptrdiff_t |
using | allocator_type = std::allocator< value_type > |
using | reference = value_type & |
using | const_reference = const value_type & |
using | pointer = typename std::allocator_traits< allocator_type >::pointer |
using | const_pointer = typename std::allocator_traits< allocator_type >::const_pointer |
using | iterator = detail::JsonIterator< Json > |
using | const_iterator = detail::JsonIterator< const Json > |
using | reverse_iterator = detail::JsonReverseIterator< iterator > |
using | const_reverse_iterator = detail::JsonReverseIterator< const_iterator > |
Public Member Functions | |
Json ()=default | |
Json (json_null_type value) noexcept | |
template<JsonStringLike T> | |
Json (T value) noexcept(false) | |
template<JsonObject T> | |
Json (T value) noexcept(false) | |
template<JsonArray T> | |
Json (T value) noexcept(false) | |
template<JsonBoolean T> | |
Json (T value) noexcept | |
template<JsonSignedInteger T> | |
Json (T value) noexcept | |
template<JsonUnsignedInteger T> | |
Json (T value) noexcept | |
template<JsonFloatingPoint T> | |
Json (T value) noexcept | |
Json (const_reference json) noexcept | |
Json (Json &&json) noexcept | |
Json (std::initializer_list< Json > initializer) noexcept | |
reference | operator= (Json json) noexcept |
json_string_type | serialize () const |
bool | is_null () const |
bool | is_string () const |
bool | is_object () const |
bool | is_object_like () const |
bool | is_array () const |
bool | is_boolean () const |
bool | is_signed_integer () const |
bool | is_unsigned_integer () const |
bool | is_float () const |
operator json_null_type () const noexcept(false) | |
template<JsonString T> | |
operator T () const &noexcept(false) | |
operator json_string_type () &&noexcept(false) | |
template<JsonObject T> | |
operator T () const &noexcept(false) | |
operator json_object_type () &&noexcept(false) | |
template<JsonArray T> | |
operator T () const &noexcept(false) | |
operator json_array_type () &&noexcept(false) | |
template<typename T , std::size_t N> | |
operator std::array< T, N > () const noexcept(false) | |
template<JsonBoolean T> | |
operator T () const noexcept | |
template<JsonNumber T> | |
operator T () const noexcept(false) | |
template<JsonStringLike T> | |
reference | at (T key) |
template<JsonStringLike T> | |
const_reference | at (T key) const |
reference | at (size_type index) |
const_reference | at (size_type index) const |
template<JsonStringLike T> | |
reference | operator[] (T key) |
template<JsonStringLike T> | |
const_reference | operator[] (T key) const |
reference | operator[] (size_type index) |
const_reference | operator[] (size_type index) const |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
iterator | begin () |
const_iterator | begin () const |
const_iterator | cbegin () const |
iterator | end () |
const_iterator | end () const |
const_iterator | cend () const |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | crbegin () const |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
const_reverse_iterator | crend () const |
bool | empty () const |
size_type | size () const |
void | resize (size_type size) |
size_type | capacity () const |
void | reserve (size_type capacity) |
void | clear () |
template<JsonStringLike Key> | |
std::pair< iterator, bool > | insert (Key key, const Json &value) |
template<JsonStringLike Key> | |
std::pair< iterator, bool > | insert (Key key, Json &&value) |
void | insert (const_iterator first, const_iterator last) |
iterator | insert (const_iterator position, const Json &value) |
iterator | insert (const_iterator position, Json &&value) |
iterator | insert (const_iterator position, size_type count, const Json &value) |
iterator | insert (const_iterator position, const_iterator first, const_iterator last) |
iterator | insert (const_iterator position, std::initializer_list< Json > initializer) |
template<JsonStringLike Key> | |
std::pair< iterator, bool > | insert_or_assign (Key key, Json &&value) |
template<JsonStringLike Key, typename Value > | |
std::pair< iterator, bool > | emplace (Key key, Value &&value) |
template<typename... Args> | |
Json::reference | emplace_back (Args &&...args) |
void | push_back (const Json &value) |
void | push_back (Json &&value) |
void | pop_back () |
template<JsonStringLike T> | |
size_type | erase (T key) |
void | erase (size_type index) |
iterator | erase (const_iterator position) |
iterator | erase (const_iterator first, const_iterator last) |
void | swap (reference json) |
template<JsonString T> | |
void | swap (T &other) |
template<JsonObject T> | |
void | swap (T &other) |
template<JsonArray T> | |
void | swap (T &other) |
void | merge (Json &other) |
void | merge (Json &&other) |
template<JsonObject T> | |
void | merge (T &other) |
template<JsonObject T> | |
void | merge (T &&other) |
template<JsonStringLike T> | |
size_type | count (T key) const |
template<JsonStringLike T> | |
iterator | find (T key) |
template<JsonStringLike T> | |
const_iterator | find (T key) const |
template<JsonStringLike T> | |
bool | contains (T key) const |
template<JsonString T> | |
operator T () const &noexcept(false) | |
template<JsonObject T> | |
operator T () const &noexcept(false) | |
template<JsonArray T> | |
operator T () const &noexcept(false) | |
Friends | |
struct | std::hash< Json > |
bool | operator== (const_reference json1, const_reference json2) |
bool | operator!= (const_reference json1, const_reference json2) |
bool | operator< (const_reference json1, const_reference json2) |
bool | operator<= (const_reference json1, const_reference json2) |
bool | operator> (const_reference json1, const_reference json2) |
bool | operator>= (const_reference json1, const_reference json2) |
Class to represent JSON values defined by https://www.json.org.
This class is designed to treat JSON as a first-class container, and to feel as easy to use as a Python dictionary.
There are a myriad of user-friendly initializers to create a JSON value from any compatible type:
A JSON string is a Unicode string. Internally, strings are stored with UTF-8 encoding. However, all methods that accept a JSON string will accept ASCII, UTF-8, UTF-16, and UTF-32 encoded strings. All strings are validated for strict Unicode compliance and converted to UTF-8. Further, the provided string type may be an STL string, a null-terminated character array, or a string view. For example: fly::Json json = "This is an ASCII string"; fly::Json json = u8"This is a UTF-8 string"; fly::Json json = u"This is a UTF-16 string"; fly::Json json = U"This is a UTF-32 string"; fly::Json json = L"This is a wide string"; // UTF-16 on Windows, UTF-32 on Linux & macOS. std::string string = "This is an ASCII string"; fly::Json json = string; std::u32string string = "This is a UTF-32 string"; std::u32string_view view = string; fly::Json json = view; A JSON object may be created from a std::map, std::unordered_multimap, etc., as long as the map key is a JSON string (where any of the above Unicode encodings are valid). Further, initializer lists with mixed types are also valid. For example: std::map<std::string, int> map = {{"key1", 1}, {"key2", 2}}; fly::Json json = map; std::unordered_map<std::u16string, int> map = {{u"key1", 1}, {u"key2", 2}}; fly::Json json = map; fly::Json json = {{"key1", nullptr}, {u8"key2", L"value2"}, {U"key3", 123.89f}}; A JSON array may be created from a std::vector, std::list, std::array, etc. Further, initializer lists with mixed types are also valid. For example: std::vector<std::string> array = {"value1", "value2"}; fly::Json json = array; std::array<std::u8string, 2> array = {u8"value1", u8"value2"}; fly::Json json = array; fly::Json json = {"value1", u8"value2", nullptr, 123.89f}; A JSON boolean, number, or null value may be created from analogous C++ plain-old-data types. Internally, 64-bit integers are used for storing integer numbers and long doubles for floating-point numbers. The signedness of the 64-bit integer is the same as the integer from which the JSON value is created. For example: fly::Json json = true; fly::Json json = -12389; fly::Json json = 123.89f; fly::Json json = nullptr;
A JSON value may be converted to any compatible C++ type. Attempting to convert a JSON value to an incompatible type is considered exceptional. Further, conversions must be explicit. To define conversion operators implicitly would introduce ambiguity in which conversion operator the compiler should choose. For example:
fly::Json json = { 1, 2, 3, 4 }; std::vector<int> vector(json); // Would not compile if conversions were implicit.
Which JSON conversion operator should be called for the std::vector constructor? Conversions from a JSON value to std::vector and std::size_t are defined, creating ambiguity in which std::vector constructor would be called (copy constructor or count constructor), even though the std::size_t converter would actually throw an exception. Explicit conversion operators remove this ambiguity.
Converting a JSON string to a string type permits the same Unicode flexibility as creating the JSON string. For example: fly::Json json = "This is an ASCII string"; std::string string(json); std::u8string string(json); std::wstring string(json); A restriction is that while creating a JSON value from a character array is allowed, converting a JSON value to a character array is not allowed. There is no safe way to do the following without allocating memory that the caller must remember to free: fly::Json json = "string"; char *string = json; // Will not compile. Converting other JSON types works similarly. Like JSON strings, the keys of the C++ type may be any compatible string type. fly::Json json = {{"key1", 1}, {u8"key2", "2"}}; std::map<std::u32string, int> map(json); // map = {{U"key1", 1}, {U"key2", 2}} fly::Json json = {"value1", u8"value2", nullptr, 123.89f}; std::vector<std::string> array(json); // array = {"value1", "value2", "null", "123.89"} fly::Json json = true; bool value(json); fly::Json json = 12389; std::uint16_t value(json); fly::Json json = -123.89f; float value(json); Some leniency is allowed for converting a JSON value to a type which differs from the type of the JSON value itself: JSON strings may be converted to numeric values if the string represents a number. For example, the string "12389" may be converted to an integer. The string "abc" may not. Numeric JSON types may be converted to a string type. All JSON types may be converted to a boolean. String, object, and array JSON values will convert based on whether the value is empty. JSON numbers will convert based on whether the value is non-zero. Null JSON values always convert to false. JSON numbers may be converted to any numeric type. For example, a floating-point JSON value may be converted to an integer.
Lastly, this class defines the canonical interfaces of STL container types. This includes element accessor, iterator, modifier, and capacity/lookup operations.
using fly::Json::value_type = Json |
Aliases for canonical STL container member types.
|
default |
Default constructor. Intializes the Json instance to a null value.
|
noexcept |
Null constructor. Intializes the Json instance to a null value.
value | The null value. |
|
noexcept |
String constructor. Intializes the Json instance to a string value. The SFINAE declaration allows construction of a string value from any string-like type (e.g. std::string, char8_t[], std::u16string_view).
T | The string-like type. |
value | The string-like value. |
JsonException | If the string-like value is not valid. |
|
noexcept |
Object constructor. Intializes the Json instance to an object's values. The SFINAE declaration allows construction of an object value from any object-like type (e.g. std::map, std::multimap).
T | The object-like type. |
value | The object-like value. |
JsonException | If an object key is not a valid string. |
|
noexcept |
Array constructor. Intializes the Json instance to an array's values. The SFINAE declaration allows construction of an array value from any array-like type (e.g. std::list, std::vector).
T | The array-like type. |
value | The array-like value. |
JsonException | If an string-like value in the array is not valid. |
|
noexcept |
Boolean constructor. Intializes the Json instance to a boolean value. The SFINAE declaration forbids construction of a boolean value from any non-boolean type (e.g. int could be implicitly cast to bool).
T | The boolean type. |
value | The boolean value. |
|
noexcept |
Signed integer constructor. Intializes the Json instance to a signed integer value. The SFINAE declaration allows construction of a signed integer value from any signed type (e.g. char, int, int64_t).
T | The signed type. |
value | The signed value. |
|
noexcept |
Unsigned integer constructor. Intializes the Json instance to an unsigned integer value. The SFINAE declaration allows construction of an unsigned integer value from any unsigned type (e.g. unsigned char, unsigned int, uint64_t).
T | The unsigned type. |
value | The unsigned value. |
|
noexcept |
Floating-point constructor. Intializes the Json instance to a floating-point value. The SFINAE declaration allows construction of a floating-point value from any floating-point type (e.g. float, double).
T | The floating-point type. |
value | The floating-point value. |
|
noexcept |
|
noexcept |
|
noexcept |
Initializer list constructor. Intializes the Json instance with an initializer list. Creates either an object or an array instance. If all values in the initializer list are object-like (see IsObjectLike()), then the Json instance is created as an object. Otherwise, it is created as an array.
initializer | The initializer list. |
Json::reference fly::Json::at | ( | size_type | index | ) |
Array read-only accessor.
If the Json instance is an array, perform a lookup on the array with an index.
index | The index to lookup. |
JsonException | If the Json instance is not an array or the index does not exist. |
Json::const_reference fly::Json::at | ( | size_type | index | ) | const |
Array read-only accessor.
If the Json instance is an array, perform a lookup on the array with an index.
index | The index to lookup. |
JsonException | If the Json instance is not an array or the index does not exist. |
Json::reference fly::Json::at | ( | T | key | ) |
Object read-only accessor. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
If the Json instance is an object, perform a lookup on the object with a key value.
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is not an object, or the key value does not exist, or the key value is invalid. |
Json::const_reference fly::Json::at | ( | T | key | ) | const |
Object read-only accessor. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
If the Json instance is an object, perform a lookup on the object with a key value.
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is not an object, or the key value does not exist, or the key value is invalid. |
Json::reference fly::Json::back | ( | ) |
Obtain a reference to the last element in the Json instance. Only valid if the Json instance is an object or an array.
For JSON objects, the returned reference will be to the value part of the back element's key-value pair.
JsonException | If the Json instance is not an object or array, or if the Json instance is empty. |
Json::const_reference fly::Json::back | ( | ) | const |
Obtain a reference to the last element in the Json instance. Only valid if the Json instance is an object or an array.
For JSON objects, the returned reference will be to the value part of the back element's key-value pair.
JsonException | If the Json instance is not an object or array, or if the Json instance is empty. |
Json::iterator fly::Json::begin | ( | ) |
Retrieve an iterator to the beginning of the Json instance.
JsonException | If the Json instance is not an object or array. |
Json::const_iterator fly::Json::begin | ( | ) | const |
Retrieve a constant iterator to the beginning of the Json instance.
JsonException | If the Json instance is not an object or array. |
Json::size_type fly::Json::capacity | ( | ) | const |
Get the number of elements that the Json instance has currently allocated space for.
If the Json instance is null, returns 0.
If the Json instance is a string or array, returns the number of elements allocated for the string or array.
If the Json instance is an object, returns the number of elements stored in the object (effectively the same as invoking Json::size).
If the Json instance is a boolean or numeric, returns 1.
Json::const_iterator fly::Json::cbegin | ( | ) | const |
Retrieve a constant iterator to the beginning of the Json instance.
JsonException | If the Json instance is not an object or array. |
Json::const_iterator fly::Json::cend | ( | ) | const |
Retrieve a constant iterator to the end of the Json instance.
JsonException | If the Json instance is not an object or array. |
void fly::Json::clear | ( | ) |
bool fly::Json::contains | ( | T | key | ) | const |
Check if there is an element in the Json instance with a given key. Only valid if the Json instance is an object. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is not an object or the key value is invalid. |
Json::size_type fly::Json::count | ( | T | key | ) | const |
Count the number of elements in the Json instance with a given key. Only valid if the Json instance is an object. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is not an object or the key value is invalid. |
Json::const_reverse_iterator fly::Json::crbegin | ( | ) | const |
Retrieve a constant reverse iterator to the beginning of the reversed Json instance.
JsonException | If the Json instance is not an object or array. |
Json::const_reverse_iterator fly::Json::crend | ( | ) | const |
Retrieve a constant reverse iterator to the end of the reversed Json instance.
JsonException | If the Json instance is not an object or array. |
std::pair< Json::iterator, bool > fly::Json::emplace | ( | Key | key, |
Value && | value | ||
) |
Construct an element in-place within the Json instance. Only valid if the Json instance is an object or null. If the Json instance is null, it is first converted to an object. The SFINAE declaration allows inserting a value with a key of any string-like type (e.g. std::string, char8_t[], std::u16string_view).
Key | The string-like type of the emplaced value's key. |
Value | The type of the emplaced value. |
key | The key of the value to emplace. |
value | The value to emplace at the given key. |
JsonException | If the Json instance is neither an object nor null. |
Json::reference fly::Json::emplace_back | ( | Args &&... | args | ) |
Construct an element in-place at the end of the Json instance. Only valid if the Json instance is an array or null. If the Json instance is null, it is first converted to an array.
Args | Variadic template arguments for value construction. |
args | The list of arguments for value construction. |
JsonException | If the Json instance is neither an array nor null. |
bool fly::Json::empty | ( | ) | const |
Json::iterator fly::Json::end | ( | ) |
Retrieve an iterator to the end of the Json instance.
JsonException | If the Json instance is not an object or array. |
Json::const_iterator fly::Json::end | ( | ) | const |
Retrieve a constant iterator to the end of the Json instance.
JsonException | If the Json instance is not an object or array. |
Json::iterator fly::Json::erase | ( | const_iterator | first, |
const_iterator | last | ||
) |
Remove all values from the Json instance in the range [first, last). Only valid if the Json instance is an object or array.
first | The beginning of the range of values to remove. |
last | The end of the range of values to remove. |
JsonException | If the Json instance is not an object or array, or the provided iterators are not for this Json instance. |
Json::iterator fly::Json::erase | ( | const_iterator | position | ) |
Remove a value from the Json instance at the provided position. Only valid if the Json instance is an object or array.
The provided position must be valid and dereferenceable. Thus the past-the-end iterator (which is valid, but is not dereferenceable) cannot be used as a position.
position | The iterator position which should be removed. |
JsonException | If the Json instance is not an object or array, the provided position is not for this Json instance, or if the provided position is past-the-end. |
void fly::Json::erase | ( | size_type | index | ) |
Remove a value from the Json instance at the provided index. Only valid if the Json instance is an array.
index | The index to remove. |
JsonException | If the Json instance is not an array or the index does not exist. |
Json::size_type fly::Json::erase | ( | T | key | ) |
Remove a value from the Json instance with the provided key. Only valid if the Json instance is an object. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
T | The string-like key type. |
key | The key value to remove. |
JsonException | If the Json instance is not an object or the key value is invalid. |
Json::iterator fly::Json::find | ( | T | key | ) |
Search for an element in the Json instance with a given key. Only valid if the Json instance is an object. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is not an object or the key value is invalid. |
Json::const_iterator fly::Json::find | ( | T | key | ) | const |
Search for an element in the Json instance with a given key. Only valid if the Json instance is an object. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is not an object or the key value is invalid. |
Json::reference fly::Json::front | ( | ) |
Obtain a reference to the first element in the Json instance. Only valid if the Json instance is an object or an array.
For JSON objects, the returned reference will be to the value part of the front element's key-value pair.
JsonException | If the Json instance is not an object or array, or if the Json instance is empty. |
Json::const_reference fly::Json::front | ( | ) | const |
Obtain a reference to the first element in the Json instance. Only valid if the Json instance is an object or an array.
For JSON objects, the returned reference will be to the value part of the front element's key-value pair.
JsonException | If the Json instance is not an object or array, or if the Json instance is empty. |
void fly::Json::insert | ( | const_iterator | first, |
const_iterator | last | ||
) |
Insert all values into the Json instance in the range [first, last). Only valid if the Json instance is an object.
first | The beginning of the range of values to insert. |
last | The end of the range of values to insert. |
JsonException | If the Json instance is not an object, the key value is invalid, the provided iterators are not for the same Json instance, or the provided iterators are for non-object Json instances. |
Json::iterator fly::Json::insert | ( | const_iterator | position, |
const Json & | value | ||
) |
Insert a copy of a Json value into the Json instance before the provided position. Only valid if the Json instance is an array.
position | The iterator position before which the value should be inserted. |
value | The Json value to insert. |
JsonException | If the Json instance is not an array or the provided position is not for this Json instance. |
Json::iterator fly::Json::insert | ( | const_iterator | position, |
const_iterator | first, | ||
const_iterator | last | ||
) |
Insert all values into the Json instance in the range [first, last) before the provided position. Only valid if the Json instance is an array. The iterators in the range [first, last) may not be iterators into this Json instance; this limitation is due to otherwise undefined behavior of std::vector.
position | The iterator position before which the value should be inserted. |
first | The beginning of the range of values to insert. |
last | The end of the range of values to insert. |
Json::iterator fly::Json::insert | ( | const_iterator | position, |
Json && | value | ||
) |
Insert a moved Json value into the Json instance before the provided position. Only valid if if the Json instance is an array.
position | The iterator position before which the value should be inserted. |
value | The Json value to insert. |
JsonException | If the Json instance is not an array or the provided position is not for this Json instance. |
Json::iterator fly::Json::insert | ( | const_iterator | position, |
size_type | count, | ||
const Json & | value | ||
) |
Insert a number of copies of a Json value into the Json instance before the provided position. Only valid if the Json instance is an array.
position | The iterator position before which the value should be inserted. |
count | The number of copies to insert. |
value | The Json value to insert. |
JsonException | If the Json instance is not an array or the provided position is not for this Json instance. |
Json::iterator fly::Json::insert | ( | const_iterator | position, |
std::initializer_list< Json > | initializer | ||
) |
Insert all values into the Json instance from the provided initializer list before the provided position instance. Only valid if the Json instance is an array.
position | The iterator position before which the value should be inserted. |
initializer | The list of values to insert. |
JsonException | If the Json instance is not an array or the provided position is not for this Json instance. |
std::pair< Json::iterator, bool > fly::Json::insert | ( | Key | key, |
const Json & | value | ||
) |
Insert a copy of a key-value pair into the Json instance. Only valid if the Json instance is an object. The SFINAE declaration allows inserting a value with a key of any string-like type (e.g. std::string, char8_t[], std::u16string_view).
Key | The string-like type of the inserted value's key. |
key | The key of the value to insert. |
value | The value to insert at the given key. |
JsonException | If the Json instance is not an object or the key value is invalid. |
std::pair< Json::iterator, bool > fly::Json::insert | ( | Key | key, |
Json && | value | ||
) |
Insert a moved key-value pair into the Json instance. Only valid if the Json instance is an object. The SFINAE declaration allows inserting a value with a key of any string-like type (e.g. std::string, char8_t[], std::u16string_view).
Key | The string-like type of the inserted value's key. |
key | The key of the value to insert. |
value | The value to insert at the given key. |
JsonException | If the Json instance is not an object or the key value is invalid. |
std::pair< Json::iterator, bool > fly::Json::insert_or_assign | ( | Key | key, |
Json && | value | ||
) |
Insert or update a moved key-value pair into the Json instance. If the provided key already exists, assigns the provided value to the key. Only valid if the Json instance is an object. The SFINAE declaration allows inserting a value with a key of any string-like type (e.g. std::string, char8_t[], std::u16string_view).
Key | The string-like type of the inserted value's key. |
key | The key of the value to insert. |
value | The value to insert at the given key. |
JsonException | If the Json instance is not an object or the key value is invalid. |
bool fly::Json::is_array | ( | ) | const |
bool fly::Json::is_boolean | ( | ) | const |
bool fly::Json::is_float | ( | ) | const |
bool fly::Json::is_null | ( | ) | const |
bool fly::Json::is_object | ( | ) | const |
bool fly::Json::is_object_like | ( | ) | const |
bool fly::Json::is_signed_integer | ( | ) | const |
bool fly::Json::is_string | ( | ) | const |
bool fly::Json::is_unsigned_integer | ( | ) | const |
void fly::Json::merge | ( | fly::Json && | other | ) |
Extract each element from a Json instance into this Json instance. Only valid if this Json instance is an object or null, and the other Json instance is an object. If this Json instance is null, it is first converted to an object.
If there is an element in the other Json instance with a key equivalent to a key of an element in this Json instance, that element is not merged.
JsonException | If this Json instance is neither an object nor null, or the other Json instance is not an object. |
void fly::Json::merge | ( | fly::Json & | other | ) |
Extract each element from a Json instance into this Json instance. Only valid if this Json instance is an object or null, and the other Json instance is an object. If this Json instance is null, it is first converted to an object.
If there is an element in the other Json instance with a key equivalent to a key of an element in this Json instance, that element is not merged.
JsonException | If this Json instance is neither an object nor null, or the other Json instance is not an object. |
void fly::Json::merge | ( | T && | other | ) |
Extract each element from an object-like type into the Json instance. Only valid if the Json instance is an object or null. If the Json instance is null, it is first converted to an object. The SFINAE declaration allows merging any object-like type (e.g. std::map, std::multimap).
If there is an element in the object-like type with a key equivalent to a key of an element in the Json instance, that element is not merged.
other | The object to merge into this Json instance. |
JsonException | If this Json instance is neither an object nor null. |
void fly::Json::merge | ( | T & | other | ) |
Extract each element from an object-like type into the Json instance. Only valid if the Json instance is an object or null. If the Json instance is null, it is first converted to an object. The SFINAE declaration allows merging any object-like type (e.g. std::map, std::multimap).
If there is an element in the object-like type with a key equivalent to a key of an element in the Json instance, that element is not merged.
other | The object to merge into this Json instance. |
JsonException | If this Json instance is neither an object nor null. |
|
explicitnoexcept |
Array move-conversion operator. If the Json instance is an array, transfers ownership of the stored value to the caller. The Json instance is set to a null value.
JsonException | If the Json instance is not an array. |
|
explicitnoexcept |
Null conversion operator. Converts the Json instance to a null type.
JsonException | If the Json instance is not null. |
|
explicitnoexcept |
Object move-conversion operator. If the Json instance is an object, transfers ownership of the stored value to the caller. The Json instance is set to a null value.
JsonException | If the Json instance is not an object. |
|
explicitnoexcept |
String move-conversion operator. If the Json instance is a string, transfers ownership of the stored value to the caller. The Json instance is set to a null value.
JsonException | If the Json instance is not a string. |
|
explicitnoexcept |
Array conversion operator. Converts the Json instance to a std::array. If the Json instance has more values than the std::array can hold, the values are dropped. If the Json instance has less values than the std::array can hold, the remainder are value-initialized.
T | The std::array value type. |
N | The std::array size. |
JsonException | If the Json instance is not an array, or a stored element could not be converted to the target array's value type. |
|
explicitnoexcept |
String conversion operator. Converts the Json instance to a string. The SFINAE declaration allows conversion to any string type (e.g. std::string, std::u8string). Also allows for converting from a numeric type (e.g. 12389) to a string type.
Note that although a Json instance can be constructed from a character array, it is not allowed to directly convert a Json instance into a character array.
T | The string type. |
JsonException | If the Json instance is not a string, or the stored value could not be converted to the target string type. |
|
explicitnoexcept |
Object conversion operator. Converts the Json instance to an object. The SFINAE declaration allows conversion to any object-like type (e.g. std::map, std::multimap).
T | The object-like type. |
JsonException | If the Json instance is not an object, or a stored element could not be converted to the target object's value type. |
|
explicitnoexcept |
Array conversion operator. Converts the Json instance to an array. The SFINAE declaration allows conversion to any array-like type (e.g. std::list, std::vector). This excludes std::array, which due to being an aggregate type, has its own explicit conversion operator.
T | The array-like type. |
JsonException | If the Json instance is not an array, or a stored element could not be converted to the target array's value type. |
|
explicitnoexcept |
Boolean conversion operator. Converts the Json instance to a boolean. For strings, objects, and arrays, returns true if the value is non-empty. For signed integers, unsigned integers, and floats, returns true if the value is non-zero. For booleans, returns the boolean value. For null, returns false.
T | The boolean type. |
|
explicitnoexcept |
Numeric conversion operator. Converts the Json instance to a numeric type. The SFINAE declaration allows conversion to any numeric type type (e.g. char, uint64_t, float) from the Json instance. Allows for converting between signed integers, unsigned integers, and floats. Also allows for converting from a numeric-like string (e.g. "12389") to a numeric type.
T | The numeric type. |
JsonException | If the Json instance is not numeric, or the stored value could not be converted to the target numeric type. |
|
noexcept |
Json::reference fly::Json::operator[] | ( | size_type | index | ) |
Array access operator.
If the Json instance is an array, perform a lookup on the array with an index. If the index is not found, the array is filled with null values up to and including the index.
If the Json instance is null, it is first converted to an array.
index | The index to lookup. |
JsonException | If the Json instance is neither an array nor null. |
Json::const_reference fly::Json::operator[] | ( | size_type | index | ) | const |
Array read-only access operator.
If the Json instance is an array, perform a lookup on the array with an index.
index | The index to lookup. |
JsonException | If the Json instance is not an array or the index does not exist. |
Json::reference fly::Json::operator[] | ( | T | key | ) |
Object access operator. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
If the Json instance is an object, perform a lookup on the object with a key value. If the key value is not found, a null Json instance will be created for that key.
If the Json instance is null, it is first converted to an object.
T | The string-like key type. |
key | The key value to lookup. |
JsonException | If the Json instance is neither an object nor null, or the key value is invalid. |
Json::const_reference fly::Json::operator[] | ( | T | key | ) | const |
Object read-only access operator. The SFINAE declaration allows lookups with any string-like type (e.g. std::string, char8_t[], std::u16string_view).
If the Json instance is an object, perform a lookup on the object with a key value.
key | The key value to lookup. |
JsonException | If the Json instance is not an object, or the key value does not exist, or the key value is invalid. |
void fly::Json::pop_back | ( | ) |
Remove the last element from the Json instance. Only valid if the Json instance is an array.
JsonException | If the Json instance is not an array or the array is empty. |
void fly::Json::push_back | ( | const Json & | value | ) |
void fly::Json::push_back | ( | Json && | value | ) |
Json::reverse_iterator fly::Json::rbegin | ( | ) |
Retrieve a reverse iterator to the beginning of the reversed Json instance.
JsonException | If the Json instance is not an object or array. |
Json::const_reverse_iterator fly::Json::rbegin | ( | ) | const |
Retrieve a constant reverse iterator to the beginning of the reversed Json instance.
JsonException | If the Json instance is not an object or array. |
Json::reverse_iterator fly::Json::rend | ( | ) |
Retrieve a reverse iterator to the end of the reversed Json instance.
JsonException | If the Json instance is not an object or array. |
Json::const_reverse_iterator fly::Json::rend | ( | ) | const |
Retrieve a constant reverse iterator to the end of the reversed Json instance.
JsonException | If the Json instance is not an object or array. |
void fly::Json::reserve | ( | size_type | capacity | ) |
Increase the capacity of the Json instance to a value that's greater or equal to the provided capacity. Only valid if the Json instance is a string or array.
capacity | The new capacity of the Json instance. |
JsonException | If the Json instance is not a string or array. |
void fly::Json::resize | ( | size_type | size | ) |
Resize the Json instance to contain the provided number of elements. Only valid if the Json instance is a string or array.
size | The new size of the Json instance. |
JsonException | If the Json instance is not a string or array. |
json_string_type fly::Json::serialize | ( | ) | const |
Json::size_type fly::Json::size | ( | ) | const |
Get the number of elements in the Json instance.
If the Json instance is null, returns 0.
If the Json instance is a string, returns the length of the string.
If the Json instance is an object or array, returns the number of elements stored in the object or array.
If the Json instance is a boolean or numeric, returns 1.
void fly::Json::swap | ( | reference | json | ) |
void fly::Json::swap | ( | T & | other | ) |
Exchange the contents of the Json instance with another string. Only valid if the Json instance is a string. The SFINAE declaration allows swapping with any string type (e.g. std::string, std::u8string).
Note that although a Json instance can be constructed from a character array, it is not allowed to directly swap a Json instance with a character array.
T | The string type to swap with. |
json | The string to swap with. |
JsonException | If the Json instance is not a string. |
void fly::Json::swap | ( | T & | other | ) |
Exchange the contents of the Json instance with another object. Only valid if the Json instance is an object. The SFINAE declaration allows swapping with any object-like type (e.g. std::map, std::multimap).
T | The object type to swap with. |
json | The object to swap with. |
JsonException | If the Json instance is not an object. |
void fly::Json::swap | ( | T & | other | ) |
Exchange the contents of the Json instance with another array. Only valid if the Json instance is an array. The SFINAE declaration allows swapping with any array-like type (e.g. std::list, std::vector).
T | The array type to swap with. |
json | The array to swap with. |
JsonException | If the Json instance is not an array. |
|
friend |
|
friend |
Less-than operator. The first Json instance is less-than the second Json instance if one of the following is true:
|
friend |
|
friend |
Equality operator. Compares two Json instances for equality. They are equal if one of the following is true:
|
friend |
|
friend |