libfilezilla
|
json parser/builder More...
#include <json.hpp>
Public Member Functions | |
json (json const &)=default | |
json (json &&) noexcept=default | |
json (json_type t) | |
Explicitly creates a value of a specific type, mainly needed for null objects. | |
json_type | type () const |
std::string | string_value () const |
Returns string, number and boolean values as string. | |
std::wstring | wstring_value () const |
Returns string, number and boolean values as wstring. | |
template<typename T , std::enable_if_t< std::is_integral_v< typename std::decay_t< T >>, int > = 0> | |
T | number_value () const |
Returns number and string values as the passed integer type. | |
template<typename T , std::enable_if_t< std::is_floating_point_v< typename std::decay_t< T >>, int > = 0> | |
T | number_value () const |
Returns number and string values as the passed floating point type. | |
bool | bool_value () const |
Returns boolean and string values as bool. | |
void | erase (std::string const &name) |
If object value, deletes child value with given name. | |
json const & | operator[] (std::string const &name) const |
If object, get the value with the given name. Returns none if not object or name doesn't exist. | |
json & | operator[] (std::string const &name) |
Returns reference to the child value with the given name. More... | |
json const & | operator[] (size_t i) const |
If array, get the value with the given index. Returns none if not array or index doesn't exist. | |
json & | operator[] (size_t i) |
Returns reference to the child value with the given index. More... | |
size_t | children () const |
For arrays and objects, returns the number of elements. | |
template<typename Bool , std::enable_if_t< std::is_same_v< bool, typename std::decay_t< Bool >>, int > = 0> | |
json & | operator= (Bool b) |
Sets type to boolean and assigns value. | |
template<typename T , std::enable_if_t< std::is_integral_v< T > &&!std::is_same_v< bool, typename std::decay_t< T >>, int > = 0> | |
json & | operator= (T n) |
Sets type to number and assigns value. | |
json & | operator= (std::string_view const &v) |
Sets type to string and assigns value. More... | |
json & | operator= (std::wstring_view const &v) |
Sets type to string and assigns value. | |
json & | operator= (json const &) |
json & | operator= (json &&) noexcept |
operator bool () const | |
bool | has_non_null_value () const |
bool | is_null () const |
bool | is_object () const |
bool | is_array () const |
bool | is_number () const |
bool | is_boolean () const |
std::string | to_string (bool pretty=false, size_t depth=0) const |
Serializes JSON structure. More... | |
void | to_string (std::string &ret, bool pretty=false, size_t depth=0) const |
Serializes JSON structure. More... | |
void | clear () |
Static Public Member Functions | |
static json | parse (std::string_view const &v, size_t max_depth=20) |
Parses JSON structure from input. More... | |
static json | parse (fz::buffer const &b, size_t max_depth=20) |
json parser/builder
json& operator= | ( | std::string_view const & | v | ) |
Sets type to string and assigns value.
Input must be UTF-8.
json& operator[] | ( | size_t | i | ) |
Returns reference to the child value with the given index.
If type is none, sets type to array. If type is array, adds a new value with the given index if needed, filling holes with none If of any other type, returns garbage
json& operator[] | ( | std::string const & | name | ) |
Returns reference to the child value with the given name.
If type is none, sets type to object. If type is object, adds a new value with name if needed If of any other type, returns garbage
|
static |
Parses JSON structure from input.
Returns none if there is any null-byte in the input
std::string to_string | ( | bool | pretty = false , |
size_t | depth = 0 |
||
) | const |
Serializes JSON structure.
Children of objects with none type are ignored. Children of arrays with none type are serialized as null.
void to_string | ( | std::string & | ret, |
bool | pretty = false , |
||
size_t | depth = 0 |
||
) | const |
Serializes JSON structure.
Children of objects with none type are ignored. Children of arrays with none type are serialized as null.
Does not clear output string