RADLib
RADical C++ application framework
RADCore::RADJsonValue Class Reference

JSON value supporting null, bool, number, string, array, and object. More...

#include <RADCore.h>

Public Member Functions

 RADJsonValue ()
 Creates JSON null. More...
 
 RADJsonValue (std::nullptr_t)
 Creates JSON null. More...
 
 RADJsonValue (bool value)
 Creates a JSON bool. More...
 
 RADJsonValue (int value)
 Creates a JSON number from int. More...
 
 RADJsonValue (int64_t value)
 Creates a JSON number from int64. More...
 
 RADJsonValue (double value)
 Creates a JSON number from double. More...
 
 RADJsonValue (const char *value)
 Creates a JSON string from C string. More...
 
 RADJsonValue (std::string value)
 Creates a JSON string. More...
 
 RADJsonValue (const RADJsonValue &other)
 Deep-copies arrays and objects so mutations do not alias the source. More...
 
 RADJsonValue (RADJsonValue &&other) noexcept=default
 Moves the value without deep-copying. More...
 
RADJsonValueoperator= (const RADJsonValue &other)
 Deep-copies arrays and objects so mutations do not alias the source. More...
 
RADJsonValueoperator= (RADJsonValue &&other) noexcept=default
 Moves the value without deep-copying. More...
 
JsonType type () const
 Returns current JSON type. More...
 
bool isNull () const
 Returns true when value is null. More...
 
bool isBool () const
 Returns true when value is bool. More...
 
bool isNumber () const
 Returns true when value is number. More...
 
bool isString () const
 Returns true when value is string. More...
 
bool isArray () const
 Returns true when value is array. More...
 
bool isObject () const
 Returns true when value is object. More...
 
bool toBool (bool defaultValue=false) const
 Converts to bool or returns defaultValue. More...
 
double toNumber (double defaultValue=0.0) const
 Converts to double or returns defaultValue. More...
 
int toInt (int defaultValue=0) const
 Converts to int or returns defaultValue. More...
 
int64_t toInt64 (int64_t defaultValue=0) const
 Converts to int64 or returns defaultValue. More...
 
std::string toString (const std::string &defaultValue={}) const
 Converts to string or returns defaultValue. More...
 
size_t size () const
 Returns array length or object member count. More...
 
bool contains (const std::string &key) const
 Returns true when object contains key. More...
 
std::vector< std::string > keys () const
 Returns object keys. More...
 
void append (RADJsonValue value)
 Appends value to an array, converting to array if needed. More...
 
void remove (const std::string &key)
 Removes key from an object. More...
 
RADJsonValueoperator[] (const std::string &key)
 Returns object member by key, creating it if needed. More...
 
const RADJsonValueoperator[] (const std::string &key) const
 Returns object member by key or null value when missing. More...
 
RADJsonValueoperator[] (size_t index)
 Returns array element by index, expanding when needed. More...
 
const RADJsonValueoperator[] (size_t index) const
 Returns array element by index or null value when missing. More...
 
std::string toJson (bool pretty=false, int indent=0) const
 Serializes this value to JSON. More...
 

Static Public Member Functions

static RADJsonValue array ()
 Creates an empty JSON array. More...
 
static RADJsonValue object ()
 Creates an empty JSON object. More...
 

Detailed Description

JSON value supporting null, bool, number, string, array, and object.

Constructor & Destructor Documentation

◆ RADJsonValue() [1/10]

RADCore::RADJsonValue::RADJsonValue ( )

Creates JSON null.

◆ RADJsonValue() [2/10]

RADCore::RADJsonValue::RADJsonValue ( std::nullptr_t  )

Creates JSON null.

◆ RADJsonValue() [3/10]

RADCore::RADJsonValue::RADJsonValue ( bool  value)

Creates a JSON bool.

◆ RADJsonValue() [4/10]

RADCore::RADJsonValue::RADJsonValue ( int  value)

Creates a JSON number from int.

◆ RADJsonValue() [5/10]

RADCore::RADJsonValue::RADJsonValue ( int64_t  value)

Creates a JSON number from int64.

◆ RADJsonValue() [6/10]

RADCore::RADJsonValue::RADJsonValue ( double  value)

Creates a JSON number from double.

◆ RADJsonValue() [7/10]

RADCore::RADJsonValue::RADJsonValue ( const char *  value)

Creates a JSON string from C string.

◆ RADJsonValue() [8/10]

RADCore::RADJsonValue::RADJsonValue ( std::string  value)

Creates a JSON string.

◆ RADJsonValue() [9/10]

RADCore::RADJsonValue::RADJsonValue ( const RADJsonValue other)

Deep-copies arrays and objects so mutations do not alias the source.

◆ RADJsonValue() [10/10]

RADCore::RADJsonValue::RADJsonValue ( RADJsonValue &&  other)
defaultnoexcept

Moves the value without deep-copying.

Member Function Documentation

◆ append()

void RADCore::RADJsonValue::append ( RADJsonValue  value)

Appends value to an array, converting to array if needed.

◆ array()

static RADJsonValue RADCore::RADJsonValue::array ( )
static

Creates an empty JSON array.

◆ contains()

bool RADCore::RADJsonValue::contains ( const std::string &  key) const

Returns true when object contains key.

◆ isArray()

bool RADCore::RADJsonValue::isArray ( ) const

Returns true when value is array.

◆ isBool()

bool RADCore::RADJsonValue::isBool ( ) const

Returns true when value is bool.

◆ isNull()

bool RADCore::RADJsonValue::isNull ( ) const

Returns true when value is null.

◆ isNumber()

bool RADCore::RADJsonValue::isNumber ( ) const

Returns true when value is number.

◆ isObject()

bool RADCore::RADJsonValue::isObject ( ) const

Returns true when value is object.

◆ isString()

bool RADCore::RADJsonValue::isString ( ) const

Returns true when value is string.

◆ keys()

std::vector<std::string> RADCore::RADJsonValue::keys ( ) const

Returns object keys.

◆ object()

static RADJsonValue RADCore::RADJsonValue::object ( )
static

Creates an empty JSON object.

◆ operator=() [1/2]

RADJsonValue& RADCore::RADJsonValue::operator= ( const RADJsonValue other)

Deep-copies arrays and objects so mutations do not alias the source.

◆ operator=() [2/2]

RADJsonValue& RADCore::RADJsonValue::operator= ( RADJsonValue &&  other)
defaultnoexcept

Moves the value without deep-copying.

◆ operator[]() [1/4]

RADJsonValue& RADCore::RADJsonValue::operator[] ( const std::string &  key)

Returns object member by key, creating it if needed.

◆ operator[]() [2/4]

const RADJsonValue& RADCore::RADJsonValue::operator[] ( const std::string &  key) const

Returns object member by key or null value when missing.

◆ operator[]() [3/4]

RADJsonValue& RADCore::RADJsonValue::operator[] ( size_t  index)

Returns array element by index, expanding when needed.

◆ operator[]() [4/4]

const RADJsonValue& RADCore::RADJsonValue::operator[] ( size_t  index) const

Returns array element by index or null value when missing.

◆ remove()

void RADCore::RADJsonValue::remove ( const std::string &  key)

Removes key from an object.

◆ size()

size_t RADCore::RADJsonValue::size ( ) const

Returns array length or object member count.

◆ toBool()

bool RADCore::RADJsonValue::toBool ( bool  defaultValue = false) const

Converts to bool or returns defaultValue.

◆ toInt()

int RADCore::RADJsonValue::toInt ( int  defaultValue = 0) const

Converts to int or returns defaultValue.

◆ toInt64()

int64_t RADCore::RADJsonValue::toInt64 ( int64_t  defaultValue = 0) const

Converts to int64 or returns defaultValue.

◆ toJson()

std::string RADCore::RADJsonValue::toJson ( bool  pretty = false,
int  indent = 0 
) const

Serializes this value to JSON.

◆ toNumber()

double RADCore::RADJsonValue::toNumber ( double  defaultValue = 0.0) const

Converts to double or returns defaultValue.

◆ toString()

std::string RADCore::RADJsonValue::toString ( const std::string &  defaultValue = {}) const

Converts to string or returns defaultValue.

◆ type()

JsonType RADCore::RADJsonValue::type ( ) const

Returns current JSON type.


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