libfilezilla
Public Member Functions | Static Public Member Functions | List of all members
json Class Referencefinal

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>
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>
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.
 
jsonoperator[] (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.
 
jsonoperator[] (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>
jsonoperator= (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>
jsonoperator= (T n)
 Sets type to number and assigns value.
 
jsonoperator= (std::string_view const &v)
 Sets type to string and assigns value. More...
 
jsonoperator= (std::wstring_view const &v)
 Sets type to string and assigns value.
 
jsonoperator= (json const &)
 
jsonoperator= (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)
 

Detailed Description

json parser/builder

Member Function Documentation

◆ operator=()

json& operator= ( std::string_view const &  v)

Sets type to string and assigns value.

Input must be UTF-8.

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

◆ parse()

static json parse ( std::string_view const &  v,
size_t  max_depth = 20 
)
static

Parses JSON structure from input.

Returns none if there is any null-byte in the input

◆ to_string() [1/2]

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.

◆ to_string() [2/2]

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


The documentation for this class was generated from the following file: