#include <json.h>
Classes | |
| class | Object |
| Insertion-ordered string->Json map with O(1) average lookup. More... | |
| class | Iterator |
| class | ItemsProxy |
| A key/value view supporting structured bindings: for (auto&& [key, val] : obj.items()) { ... } For arrays, key() is the decimal index. More... | |
Public Types | |
| enum class | Type : uint8_t { Null , Boolean , Integer , Unsigned , Float , String , Array , Object , Discarded } |
| using | Array = std::vector<Json> |
| using | iterator = Iterator<false> |
| using | const_iterator = Iterator<true> |
Public Member Functions | |
| Json () noexcept | |
| Json (std::nullptr_t) noexcept | |
| Json (bool b) noexcept | |
| template<typename T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, bool >::value, int >::type = 0> | |
| Json (T v) noexcept | |
| template<typename T, typename std::enable_if< std::is_floating_point< T >::value, int >::type = 0> | |
| Json (T v) noexcept | |
| Json (const char *s) | |
| Json (const std::string &s) | |
| Json (std::string &&s) | |
| Json (std::initializer_list< Json > init) | |
| nlohmann-style brace initialisation. | |
| Json (const Json &other) | |
| Json (Json &&other) noexcept | |
| Json & | operator= (const Json &other) |
| Json & | operator= (Json &&other) noexcept |
| ~Json () | |
| std::string | dump (int indent=-1) const |
| Type | type () const noexcept |
| bool | is_null () const noexcept |
| bool | is_boolean () const noexcept |
| bool | is_number () const noexcept |
| bool | is_number_integer () const noexcept |
| bool | is_number_unsigned () const noexcept |
| bool | is_number_float () const noexcept |
| bool | is_string () const noexcept |
| bool | is_array () const noexcept |
| bool | is_object () const noexcept |
| bool | is_discarded () const noexcept |
| bool | is_primitive () const noexcept |
| bool | is_structured () const noexcept |
| std::size_t | size () const noexcept |
| Number of elements (array/object), or 0 for null, 1 for any scalar. | |
| bool | empty () const noexcept |
| True for null, an empty array, or an empty object. | |
| Json & | operator[] (const std::string &key) |
| Json & | operator[] (const char *key) |
| const Json & | operator[] (const std::string &key) const |
| const Json & | operator[] (const char *key) const |
| Json & | operator[] (int index) |
| Json & | operator[] (std::size_t index) |
| const Json & | operator[] (int index) const |
| const Json & | operator[] (std::size_t index) const |
| Json & | at (const std::string &key) |
| Bounds/existence-checked access; throws JsonError when missing. | |
| const Json & | at (const std::string &key) const |
| Json & | at (std::size_t index) |
| const Json & | at (std::size_t index) const |
| bool | contains (const std::string &key) const |
| bool | erase (const std::string &key) |
| void | erase (std::size_t index) |
| Json & | front () |
| const Json & | front () const |
| Json & | back () |
| const Json & | back () const |
| void | push_back (const Json &value) |
| void | push_back (Json &&value) |
| template<typename... Args> | |
| Json & | emplace_back (Args &&... args) |
| void | clear () |
| template<typename T> | |
| T | get () const |
| template<typename T, typename std::enable_if<(std::is_arithmetic< T >::value||std::is_same< T, std::string >::value) &&!std::is_same< T, Json >::value, int >::type = 0> | |
| operator T () const | |
| Implicit conversion to arithmetic types and std::string, so call sites like int v = j["x"]; and std::string s = j["y"]; read naturally. | |
| template<typename T> | |
| T | value (const std::string &key, const T &default_value) const |
| value(key, default): typed object lookup with a fallback. | |
| std::string | value (const std::string &key, const char *default_value) const |
| const char* default resolves to a std::string result (nlohmann parity). | |
| iterator | begin () |
| iterator | end () |
| const_iterator | begin () const |
| const_iterator | end () const |
| const_iterator | cbegin () const |
| const_iterator | cend () const |
| ItemsProxy< false > | items () |
| ItemsProxy< true > | items () const |
| bool | operator== (const Json &other) const |
| bool | operator!= (const Json &other) const |
| Array & | as_array () |
| const Array & | as_array () const |
| Object & | as_object () |
| const Object & | as_object () const |
Static Public Member Functions | |
| static Json | array () |
| Explicit empties (also handy to force kind on an otherwise-null value). | |
| static Json | object () |
| static Json | parse (const std::string &text, std::nullptr_t=nullptr, bool allow_exceptions=true) |
| static Json | parse (const char *text, std::nullptr_t=nullptr, bool allow_exceptions=true) |
| template<typename InputIt> | |
| static Json | parse (InputIt first, InputIt last, std::nullptr_t=nullptr, bool allow_exceptions=true) |
Friends | |
| class | JsonParser |
| using librats::Json::Array = std::vector<Json> |
| using librats::Json::const_iterator = Iterator<true> |
| using librats::Json::iterator = Iterator<false> |
|
strong |
|
inlinenoexcept |
Definition at line 133 of file json.h.
Referenced by Json(), Json(), array(), at(), at(), at(), at(), back(), back(), emplace_back(), librats::Json::Object::find(), librats::Json::Object::find(), front(), front(), object(), operator!=(), operator=(), operator=(), operator==(), librats::Json::Object::operator[](), librats::Json::Object::operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), parse(), parse(), parse(), push_back(), push_back(), value(), and value().
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
| librats::Json::Json | ( | std::initializer_list< Json > | init | ) |
nlohmann-style brace initialisation.
A list whose every element is a two-element array with a string first element is read as an object; otherwise it is an array.
|
inline |
|
inlinenoexcept |
|
inlinestatic |
| Array & librats::Json::as_array | ( | ) |
| const Array & librats::Json::as_array | ( | ) | const |
| Object & librats::Json::as_object | ( | ) |
| Json & librats::Json::at | ( | const std::string & | key | ) |
| Json & librats::Json::back | ( | ) |
References Json().
Referenced by emplace_back().
|
inline |
|
inline |
|
inline |
| void librats::Json::clear | ( | ) |
|
inline |
Definition at line 250 of file json.h.
References is_object(), and obj_.
| std::string librats::Json::dump | ( | int | indent = -1 | ) | const |
|
inline |
Definition at line 264 of file json.h.
References Json(), back(), and push_back().
|
noexcept |
|
inline |
| bool librats::Json::erase | ( | const std::string & | key | ) |
| void librats::Json::erase | ( | std::size_t | index | ) |
|
inline |
Definition at line 274 of file json.h.
Referenced by operator T().
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 218 of file json.h.
References Object.
Referenced by contains(), is_structured(), value(), and value().
|
inlinenoexcept |
Definition at line 220 of file json.h.
References is_boolean(), is_null(), is_number(), and is_string().
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 223 of file json.h.
References is_array(), and is_object().
|
inline |
|
inline |
|
inlinestatic |
|
inline |
|
inline |
Definition at line 233 of file json.h.
References Json(), and operator[]().
Referenced by operator[]().
|
inline |
Definition at line 235 of file json.h.
References Json(), and operator[]().
Referenced by operator[]().
| Json & librats::Json::operator[] | ( | const std::string & | key | ) |
References Json().
Referenced by operator[]().
|
inline |
Definition at line 237 of file json.h.
References Json(), and operator[]().
Referenced by operator[]().
|
inline |
Definition at line 239 of file json.h.
References Json(), and operator[]().
|
static |
References Json().
|
static |
|
inlinestatic |
| void librats::Json::push_back | ( | const Json & | value | ) |
References Json(), and value().
Referenced by emplace_back().
|
noexcept |
|
inline |
const char* default resolves to a std::string result (nlohmann parity).
Definition at line 306 of file json.h.
References Json(), is_object(), and obj_.
|
inline |
value(key, default): typed object lookup with a fallback.
Returns the default when this is not an object or the key is absent.
Definition at line 299 of file json.h.
References Json(), is_object(), and obj_.
Referenced by push_back(), and push_back().
|
friend |
| Object* librats::Json::obj_ |
| std::string* librats::Json::str_ |