Public Types | List of all members
clan::JsonValue Class Reference
clanCore JSON

Class representing a JSON value. More...

`#include <json_value.h>`

## Public Types
enum | Type { Type::undefined, 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 float () const
| operator double () const
| operator int () const
JsonValue & | operator[] (const char *key)
| Indexers for object members or array items. More...
JsonValue & | operator[] (const std::string &key)
const JsonValue & | operator[] (const char *key) const
const JsonValue & | operator[] (const std::string &key) const
const JsonValue & | operator[] (int index) const
JsonValue & | operator[] (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_undefined () const
| Return true if value is undefined. More...
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
template<typename T >
JsonValue & | operator= (const T &value)
| Assign a new value. More...
JsonValue & | operator= (const JsonValue &value)
template<typename Type >
std::map< std::string, Type > | to_map () const
| Convert value object to a std::map with the template specified value type. More...
template<typename Type >
std::vector< Type > | to_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 (bool value)
| JsonValue (int value)
| JsonValue (double value)
| JsonValue (const char *value)
| JsonValue (const std::string &value)

## Detailed Description

Class representing a JSON value.

## Constructor & Destructor Documentation

clan::JsonValue::JsonValue | ( |  | ) |
| inline

Constructs a value.

References clan::undefined.

Referenced by array(), boolean(), null(), number(), object(), operator=(), and string().

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

clan::JsonValue::JsonValue | ( | bool | value | ) |
| inline

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

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

clan::JsonValue::JsonValue | ( | const char * | value | ) |
| inline

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

## Member Function Documentation

static JsonValue clan::JsonValue::array | ( |  | ) |
| inline static

Create a array value.

References array, and JsonValue().

static JsonValue clan::JsonValue::boolean | ( | bool | value | ) |
| inline static

Create a boolean value.

References JsonValue().

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

Create a value from UTF-8 JSON string.

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

Get array items.

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

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

Get object members.

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

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

Get size of value.

References array, object, and string.

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

Get value type.

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

Return true if value is an array.

References array.

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

Return true if value is a boolean.

References boolean.

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

Return true if value is null.

References null.

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

Return true if value is a number.

References number.

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

Return true if value is an object.

References object.

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

Return true if value is a string.

References string.

bool clan::JsonValue::is_undefined | ( |  | ) | const
| inline

Return true if value is undefined.

References undefined.

static JsonValue clan::JsonValue::null | ( |  | ) |
| inline static

Create a null value.

References JsonValue(), and null.

static JsonValue clan::JsonValue::number | ( | int | value | ) |
| inline static

Create a number value.

References JsonValue().

static JsonValue clan::JsonValue::number | ( | double | value | ) |
| inline static

References JsonValue().

static JsonValue clan::JsonValue::object | ( |  | ) |
| inline static

Create a object value.

References JsonValue(), and object.

Referenced by to_map().

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

Convert value to a different type.

References to_boolean().

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

References to_double().

clan::JsonValue::operator float | ( |  | ) | const
| inline

References to_float().

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

References to_int().

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

References to_string().

template<typename T >

JsonValue& clan::JsonValue::operator= | ( | const T & | value | ) |
| inline

Assign a new value.

References JsonValue().

JsonValue& clan::JsonValue::operator= | ( | const JsonValue & | value | ) |
| inline

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

Indexers for object members or array items.

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

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

References clan::undefined.

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

References clan::undefined.

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

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

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

Create a string value.

References JsonValue().

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

Convert value object to a boolean.

References boolean.

Referenced by operator bool().

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

Convert value object to a double.

References number.

Referenced by operator double().

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

Convert value object to a float.

References number.

Referenced by operator float().

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

Convert value object to an int.

References number.

Referenced by operator int().

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

Create an UTF-8 JSON string for the value.

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

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 object.

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

Convert value object to a string.

References string.

Referenced by operator std::string().

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 array.

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

- json_value.h