clan::JsonValue Class Reference

Class representing a JSON value. More...

#include <json_value.h>

Public Types

enum  Type {
  type_null, type_object, type_array, type_string,
  type_number, type_boolean
}
 value type More...
 

Public Member Functions

Attributes
 operator bool () const
 Convert value to a different type. More...
 
 operator std::string () const
 
 operator double () const
 
 operator int () const
 
JsonValueoperator[] (const char *key)
 Indexers for object members or array items. More...
 
JsonValueoperator[] (const std::string &key)
 
const JsonValueoperator[] (int index) const
 
JsonValueoperator[] (int index)
 
Type get_type () const
 Get value type. More...
 
size_t get_size () const
 Get size of value. More...
 
std::map< std::string, JsonValue > & get_members ()
 Get object members. More...
 
const std::map< std::string, JsonValue > & get_members () const
 
std::vector< JsonValue > & get_items ()
 Get array items. More...
 
const std::vector< JsonValue > & get_items () const
 
bool is_null () const
 Return true if value is null. More...
 
bool is_object () const
 Return true if value is an object. More...
 
bool is_array () const
 Return true if value is an array. More...
 
bool is_string () const
 Return true if value is a string. More...
 
bool is_number () const
 Return true if value is a number. More...
 
bool is_boolean () const
 Return true if value is a boolean. More...
 
std::string to_string () const
 Convert value object to a string. More...
 
int to_int () const
 Convert value object to an int. More...
 
float to_float () const
 Convert value object to a float. More...
 
double to_double () const
 Convert value object to a double. More...
 
bool to_boolean () const
 Convert value object to a boolean. More...
 
Operations
JsonValueoperator= (const char *value)
 Assign a new value. More...
 
JsonValueoperator= (const std::string &value)
 
JsonValueoperator= (int value)
 
JsonValueoperator= (double value)
 
JsonValueoperator= (bool value)
 
template<typename Type >
std::map< std::string, Typeto_map () const
 Convert value object to a std::map with the template specified value type. More...
 
template<typename Type >
std::vector< Typeto_vector () const
 Convert value array to a std::vector with the template specified value type. More...
 
std::string to_json () const
 Create an UTF-8 JSON string for the value. More...
 
void to_json (std::string &result) const
 

Construction

static JsonValue object ()
 Create a object value. More...
 
static JsonValue array ()
 Create a array value. More...
 
static JsonValue null ()
 Create a null value. More...
 
static JsonValue string (const std::string &value)
 Create a string value. More...
 
static JsonValue boolean (bool value)
 Create a boolean value. More...
 
static JsonValue number (int value)
 Create a number value. More...
 
static JsonValue number (double value)
 
static JsonValue from_json (const std::string &json)
 Create a value from UTF-8 JSON string. More...
 
 JsonValue ()
 Constructs a value. More...
 
 JsonValue (Type type)
 
 JsonValue (const std::string &value)
 
 JsonValue (int value)
 
 JsonValue (double value)
 
 JsonValue (bool value)
 

Detailed Description

Class representing a JSON value.

Member Enumeration Documentation

◆ Type

value type

Enumerator
type_null 
type_object 
type_array 
type_string 
type_number 
type_boolean 

Constructor & Destructor Documentation

◆ JsonValue() [1/6]

clan::JsonValue::JsonValue ( )
inline

Constructs a value.

◆ JsonValue() [2/6]

clan::JsonValue::JsonValue ( Type  type)
inline

◆ JsonValue() [3/6]

clan::JsonValue::JsonValue ( const std::string &  value)
inline

◆ JsonValue() [4/6]

clan::JsonValue::JsonValue ( int  value)
inline

◆ JsonValue() [5/6]

clan::JsonValue::JsonValue ( double  value)
inline

◆ JsonValue() [6/6]

clan::JsonValue::JsonValue ( bool  value)
inlineexplicit

Member Function Documentation

◆ array()

static JsonValue clan::JsonValue::array ( )
inlinestatic

Create a array value.

◆ boolean()

static JsonValue clan::JsonValue::boolean ( bool  value)
inlinestatic

Create a boolean value.

◆ from_json()

static JsonValue clan::JsonValue::from_json ( const std::string &  json)
static

Create a value from UTF-8 JSON string.

◆ get_items() [1/2]

std::vector<JsonValue>& clan::JsonValue::get_items ( )
inline

Get array items.

◆ get_items() [2/2]

const std::vector<JsonValue>& clan::JsonValue::get_items ( ) const
inline

◆ get_members() [1/2]

std::map<std::string, JsonValue>& clan::JsonValue::get_members ( )
inline

Get object members.

◆ get_members() [2/2]

const std::map<std::string, JsonValue>& clan::JsonValue::get_members ( ) const
inline

◆ get_size()

size_t clan::JsonValue::get_size ( ) const
inline

Get size of value.

◆ get_type()

Type clan::JsonValue::get_type ( ) const
inline

Get value type.

◆ is_array()

bool clan::JsonValue::is_array ( ) const
inline

Return true if value is an array.

◆ is_boolean()

bool clan::JsonValue::is_boolean ( ) const
inline

Return true if value is a boolean.

◆ is_null()

bool clan::JsonValue::is_null ( ) const
inline

Return true if value is null.

◆ is_number()

bool clan::JsonValue::is_number ( ) const
inline

Return true if value is a number.

◆ is_object()

bool clan::JsonValue::is_object ( ) const
inline

Return true if value is an object.

◆ is_string()

bool clan::JsonValue::is_string ( ) const
inline

Return true if value is a string.

◆ null()

static JsonValue clan::JsonValue::null ( )
inlinestatic

Create a null value.

◆ number() [1/2]

static JsonValue clan::JsonValue::number ( int  value)
inlinestatic

Create a number value.

◆ number() [2/2]

static JsonValue clan::JsonValue::number ( double  value)
inlinestatic

◆ object()

static JsonValue clan::JsonValue::object ( )
inlinestatic

Create a object value.

◆ operator bool()

clan::JsonValue::operator bool ( ) const
inline

Convert value to a different type.

◆ operator double()

clan::JsonValue::operator double ( ) const
inline

◆ operator int()

clan::JsonValue::operator int ( ) const
inline

◆ operator std::string()

clan::JsonValue::operator std::string ( ) const
inline

◆ operator=() [1/5]

JsonValue& clan::JsonValue::operator= ( const char *  value)
inline

Assign a new value.

◆ operator=() [2/5]

JsonValue& clan::JsonValue::operator= ( const std::string &  value)
inline

◆ operator=() [3/5]

JsonValue& clan::JsonValue::operator= ( int  value)
inline

◆ operator=() [4/5]

JsonValue& clan::JsonValue::operator= ( double  value)
inline

◆ operator=() [5/5]

JsonValue& clan::JsonValue::operator= ( bool  value)
inline

◆ operator[]() [1/4]

JsonValue& clan::JsonValue::operator[] ( const char *  key)
inline

Indexers for object members or array items.

◆ operator[]() [2/4]

JsonValue& clan::JsonValue::operator[] ( const std::string &  key)
inline

◆ operator[]() [3/4]

const JsonValue& clan::JsonValue::operator[] ( int  index) const
inline

◆ operator[]() [4/4]

JsonValue& clan::JsonValue::operator[] ( int  index)
inline

◆ string()

static JsonValue clan::JsonValue::string ( const std::string &  value)
inlinestatic

Create a string value.

◆ to_boolean()

bool clan::JsonValue::to_boolean ( ) const
inline

Convert value object to a boolean.

References clan::JsonException::JsonException().

◆ to_double()

double clan::JsonValue::to_double ( ) const
inline

Convert value object to a double.

References clan::JsonException::JsonException().

◆ to_float()

float clan::JsonValue::to_float ( ) const
inline

Convert value object to a float.

References clan::JsonException::JsonException().

◆ to_int()

int clan::JsonValue::to_int ( ) const
inline

Convert value object to an int.

References clan::JsonException::JsonException().

◆ to_json() [1/2]

std::string clan::JsonValue::to_json ( ) const

Create an UTF-8 JSON string for the value.

◆ to_json() [2/2]

void clan::JsonValue::to_json ( std::string &  result) const

◆ to_map()

template<typename Type >
std::map<std::string, Type> clan::JsonValue::to_map ( ) const
inline

Convert value object to a std::map with the template specified value type.

References clan::JsonException::JsonException().

◆ to_string()

std::string clan::JsonValue::to_string ( ) const
inline

Convert value object to a string.

References clan::JsonException::JsonException().

◆ to_vector()

template<typename Type >
std::vector<Type> clan::JsonValue::to_vector ( ) const
inline

Convert value array to a std::vector with the template specified value type.

References clan::JsonException::JsonException().


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