Library interface, represents a valid JSON value. More...
#include <djson/json.hpp>
Public Types | |
| using | Type = JsonType |
Public Member Functions | |
| Json ()=default | |
| ~Json ()=default | |
| Json (Json &&)=default | |
| auto | operator= (Json &&) -> Json &=default |
| Json (Json const &other) | |
| auto | operator= (Json const &other) -> Json & |
| explicit (false) Json(std | |
| auto | get_type () const -> Type |
| Obtain the value type of this Json. | |
| auto | is_null () const -> bool |
| auto | is_boolean () const -> bool |
| auto | is_number () const -> bool |
| auto | is_string () const -> bool |
| auto | is_array () const -> bool |
| auto | is_object () const -> bool |
| auto | as_bool (bool fallback={}) const -> bool |
| auto | as_double (double fallback={}) const -> double |
| auto | as_u64 (std::uint64_t fallback={}) const -> std::uint64_t |
| auto | as_i64 (std::int64_t fallback={}) const -> std::int64_t |
| auto | as_string_view (std::string_view fallback={}) const -> std::string_view |
| auto | as_string (std::string_view const fallback={}) const -> std::string |
| template<NumericT Type> | |
| auto | as_number (Type const fallback={}) const -> Type |
| template<GettableT Type> | |
| auto | as (Type const &fallback={}) const -> Type |
| auto | as_array () const -> std::span< dj::Json const > |
| auto | as_object () const -> StringTable< dj::Json > const & |
| void | set_null () |
| void | set_boolean (bool value) |
| void | set_string (std::string_view value) |
| void | set_number (std::int64_t value) |
| void | set_number (std::uint64_t value) |
| void | set_number (double value) |
| void | set_value (Json value) |
| template<NumericT Type> | |
| void | set_number (Type const value) |
| template<SettableT Type> | |
| void | set (Type const &value) |
| void | set_array () |
| Set value to empty Array. | |
| void | set_object () |
| Set value to empty Object. | |
| auto | push_back (Json value={}) -> Json & |
| Insert value at the end of the Array. Converts to empty Array value first if not already one. | |
| auto | insert_or_assign (std::string key, Json value) -> Json & |
| Insert value associated with key into the Object. Converts to empty Object value first if not already one. | |
| auto | operator[] (std::string_view key) const -> Json const & |
| Obtain the value associated with the passed key. | |
| auto | operator[] (std::string_view key) -> Json & |
| Obtain the value associated with the passed key. | |
| auto | operator[] (std::size_t index) const -> Json const & |
| Obtain the value at the passed index. | |
| auto | operator[] (std::size_t index) -> Json & |
| Obtain the value at the passed index. | |
| auto | serialize (SerializeOptions const &options={}) const -> std::string |
| Serialize value as a string. | |
| auto | to_file (std::string_view path, SerializeOptions const &options={}) const -> bool |
| Write serialized string to a file. | |
| operator bool () const | |
Static Public Member Functions | |
| static auto | parse (std::string_view text, ParseMode mode=ParseMode::Auto) -> Result |
| Parse JSON text. | |
| static auto | from_file (std::string_view path, ParseMode mode=ParseMode::Auto) -> Result |
| Parse JSON from a file. | |
| static auto | empty_array () -> Json const & |
| Obtain a Json representing an empty Array value. | |
| static auto | empty_object () -> Json const & |
| Obtain a Json representing an empty Object value. | |
Friends | |
| class | detail::Parser |
| void | swap (Json &a, Json &b) noexcept |
Library interface, represents a valid JSON value.
| using dj::Json::Type = JsonType |
|
default |
|
default |
|
default |
| dj::Json::Json | ( | Json const & | other | ) |
| auto dj::Json::as_array | ( | ) | const -> std::span< dj::Json const > |
| auto dj::Json::as_bool | ( | bool | fallback = {} | ) | const -> bool |
| auto dj::Json::as_double | ( | double | fallback = {} | ) | const -> double |
| auto dj::Json::as_i64 | ( | std::int64_t | fallback = {} | ) | const -> std::int64_t |
| auto dj::Json::as_object | ( | ) | const -> StringTable< dj::Json > const & |
|
inline |
| auto dj::Json::as_string_view | ( | std::string_view | fallback = {} | ) | const -> std::string_view |
| auto dj::Json::as_u64 | ( | std::uint64_t | fallback = {} | ) | const -> std::uint64_t |
|
static |
Obtain a Json representing an empty Array value.
|
static |
Obtain a Json representing an empty Object value.
|
inline |
|
static |
Insert value associated with key into the Object. Converts to empty Object value first if not already one.
| key | Key to associate value with. |
| value | Value to insert. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
| auto dj::Json::operator[] | ( | std::size_t | index | ) | -> Json & |
Obtain the value at the passed index.
| index | Index to access value for. |
| auto dj::Json::operator[] | ( | std::size_t | index | ) | const -> Json const & |
Obtain the value at the passed index.
| index | Index to access value for. |
| auto dj::Json::operator[] | ( | std::string_view | key | ) | -> Json & |
Obtain the value associated with the passed key.
| key | Key to lookup value for. |
| auto dj::Json::operator[] | ( | std::string_view | key | ) | const -> Json const & |
Obtain the value associated with the passed key.
| key | Key to lookup value for. |
|
static |
Insert value at the end of the Array. Converts to empty Array value first if not already one.
| value | Value to insert. |
| auto dj::Json::serialize | ( | SerializeOptions const & | options = {} | ) | const -> std::string |
Serialize value as a string.
| options | Serialization options. |
|
inline |
| void dj::Json::set_array | ( | ) |
Set value to empty Array.
| void dj::Json::set_boolean | ( | bool | value | ) |
| void dj::Json::set_null | ( | ) |
| void dj::Json::set_number | ( | double | value | ) |
| void dj::Json::set_number | ( | std::int64_t | value | ) |
| void dj::Json::set_number | ( | std::uint64_t | value | ) |
|
inline |
| void dj::Json::set_object | ( | ) |
Set value to empty Object.
| void dj::Json::set_string | ( | std::string_view | value | ) |
| void dj::Json::set_value | ( | Json | value | ) |
| auto dj::Json::to_file | ( | std::string_view | path, |
| SerializeOptions const & | options = {} |
||
| ) | const -> bool |
Write serialized string to a file.
| path | Path to write to. |
| options | Serialization options. |
|
friend |