10Duke Scale C++ Client
Loading...
Searching...
No Matches
tenduke::json Namespace Reference

Detailed Description

JSON support.

Interfaces for simple JSON support.

Namespaces

namespace  cjson
 Implementation of JSON service interfaces using cJSON.
 

Classes

class  JSONArray
 A JSON array. More...
 
class  JSONArrayBuilder
 Builds JSON-array. More...
 
class  JSONBoolean
 JSON boolean. More...
 
class  JSONBuilder
 NOTE: This class is for now INTERNAL USE ONLY. More...
 
class  JSONElement
 Superclass of JSON elements. More...
 
class  JSONException
 Thrown on JSON-related errors. More...
 
class  JSONNumber
 Represents JSON number. More...
 
class  JSONObject
 JSON object element. More...
 
class  JSONObjectBuilder
 Builds JSON objects. More...
 
class  JSONParser
 Parser for JSON documents. More...
 
class  JSONParsingException
 Thrown when JSON parsing failed. More...
 
class  JSONString
 JSON string element. More...
 

Functions

tenduke::json::JSONArraycastToArray (tenduke::json::JSONElement *element)
 Type-casts given element to JSONArray.
 
tenduke::json::JSONArraycastToArray (const std::shared_ptr< tenduke::json::JSONElement > &element)
 Type-casts given element to JSONArray.
 
tenduke::json::JSONArraycastToArray (const std::unique_ptr< tenduke::json::JSONElement > &element)
 Type-casts given element to JSONArray.
 
tenduke::json::JSONObjectcastToObject (tenduke::json::JSONElement *element)
 Type-casts given element to JSONObject.
 
tenduke::json::JSONObjectcastToObject (const std::shared_ptr< tenduke::json::JSONElement > &element)
 Type-casts given element to JSONObject.
 
tenduke::json::JSONObjectcastToObject (const std::unique_ptr< tenduke::json::JSONElement > &element)
 Type-casts given element to JSONObject.
 
std::int64_t toInt64 (const JSONElement *element, bool throwIfInvalid=true, std::int64_t defaultValue=0)
 Returns given element as std::int_64t, assuming the element is JSONNumber.
 
std::int64_t toInt64 (const JSONElement &element, bool throwIfInvalid=true, std::int64_t defaultValue=0)
 Returns given element as std::int_64t, assuming the element is JSONNumber.
 
bool isBooleanTrue (const JSONElement *element)
 Returns true if element is JSONBoolean with value true.
 
bool isBooleanTrue (const std::unique_ptr< const JSONElement > &element)
 Returns true if element is JSONBoolean with value true.
 
bool isBooleanTrue (const std::shared_ptr< const JSONElement > &element)
 Returns true if element is JSONBoolean with value true.
 
tenduke::json::JSONArraygetArray (const json::JSONObject *object, const std::string &propertyName)
 Helper to get JSON object property as tenduke::json::JSONArray.
 
bool getBool (const json::JSONObject *object, const std::string &propertyName, bool defaultValue=false)
 Helper to get JSON object property as boolean.
 
std::int32_t getInt32 (const tenduke::json::JSONObject *object, const std::string &propertyName, std::int32_t defaultValue=0)
 Helper to get numeric JSON object property as std::int32_t.
 
std::int64_t getInt64 (const tenduke::json::JSONObject *object, const std::string &propertyName, std::int64_t defaultValue=0)
 Helper to get numeric JSON object property as std::int64_t.
 
tenduke::json::JSONNumbergetNumber (const tenduke::json::JSONObject *object, const std::string &propertyName)
 Helper to get JSON object property as tenduke::json::JSONNumber.
 
tenduke::json::JSONObjectgetObject (const tenduke::json::JSONObject *object, const std::string &propertyName)
 Helper to get JSON object property as tenduke::json::JSONObject.
 
std::string getStdString (const tenduke::json::JSONObject &object, const std::string &propertyName, const std::string &defaultValue={})
 Helper to get JSON object property as std::string.
 
std::string getStdString (const tenduke::json::JSONObject *object, const std::string &propertyName, const std::string &defaultValue={})
 Helper to get JSON object property as std::string.
 
std::map< std::string, std::string > toMapOfStrings (const tenduke::json::JSONObject *object)
 Converts a tenduke::json::JSONObject to a flattened map of strings, where the key is name of the object property and value is result of calling tenduke::json::JSONElement.asString() on the property element.
 

Function Documentation

◆ castToArray() [1/3]

tenduke::json::JSONArray * tenduke::json::castToArray ( const std::shared_ptr< tenduke::json::JSONElement > &  element)

Type-casts given element to JSONArray.

Parameters
element-
Returns
the element as JSONArray. Returns nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined()
Exceptions
`::tenduke::json::JSONException`if the element is not JSON array

◆ castToArray() [2/3]

tenduke::json::JSONArray * tenduke::json::castToArray ( const std::unique_ptr< tenduke::json::JSONElement > &  element)

Type-casts given element to JSONArray.

Parameters
element-
Returns
the element as JSONArray. Returns nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined()
Exceptions
`::tenduke::json::JSONException`if the element is not JSON array

◆ castToArray() [3/3]

xdjson::JSONArray * tenduke::json::castToArray ( tenduke::json::JSONElement element)

Type-casts given element to JSONArray.

Parameters
element-
Returns
the element as JSONArray. Returns nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined()
Exceptions
`::tenduke::json::JSONException`if the element is not JSON array

◆ castToObject() [1/3]

xdjson::JSONObject * tenduke::json::castToObject ( const std::shared_ptr< tenduke::json::JSONElement > &  element)

Type-casts given element to JSONObject.

Parameters
element-
Returns
the element as JSONObject. Returns nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined()
Exceptions
`::tenduke::json::JSONException`if the element is not JSON object

◆ castToObject() [2/3]

xdjson::JSONObject * tenduke::json::castToObject ( const std::unique_ptr< tenduke::json::JSONElement > &  element)

Type-casts given element to JSONObject.

Parameters
element-
Returns
the element as JSONObject. Returns nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined()
Exceptions
`::tenduke::json::JSONException`if the element is not JSON object

◆ castToObject() [3/3]

xdjson::JSONObject * tenduke::json::castToObject ( tenduke::json::JSONElement element)

Type-casts given element to JSONObject.

Parameters
element-
Returns
the element as JSONObject. Returns nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined()
Exceptions
`::tenduke::json::JSONException`if the element is not JSON object

◆ getArray()

xdjson::JSONArray * tenduke::json::getArray ( const json::JSONObject object,
const std::string &  propertyName 
)

Helper to get JSON object property as tenduke::json::JSONArray.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
Returns
the property cast to tenduke::json::JSONArray. Returns nullptr, if object does not contain such property, or if the property is null or undefined.
Exceptions
`::tenduke::json::JSONException`if the property is not JSON array.

◆ getBool()

bool tenduke::json::getBool ( const json::JSONObject object,
const std::string &  propertyName,
bool  defaultValue = false 
)

Helper to get JSON object property as boolean.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
defaultValuedefault value to return if the object does not have such property
Returns
true, if the JSON object has such property and the property is a JSON boolean with value true. Returns false if the property is a JSON boolean with value false. Returns parameter defaultValue if the JSON object does not have such property.
Exceptions
`::tenduke::json::JSONException`if the property is not JSON boolean.

◆ getInt32()

std::int32_t tenduke::json::getInt32 ( const tenduke::json::JSONObject object,
const std::string &  propertyName,
std::int32_t  defaultValue = 0 
)

Helper to get numeric JSON object property as std::int32_t.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
defaultValuedefault value to return if the object does not have such property
Returns
The value of the numeric JSON object property as std::int_32t. Returns parameter defaultValue if the JSON object does not have such property.
Exceptions
`::tenduke::json::JSONException`if the property is not JSON number.

◆ getInt64()

std::int64_t tenduke::json::getInt64 ( const tenduke::json::JSONObject object,
const std::string &  propertyName,
std::int64_t  defaultValue = 0 
)

Helper to get numeric JSON object property as std::int64_t.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
defaultValuedefault value to return if the object does not have such property
Returns
The value of the numeric JSON object property as std::int_64t. Returns parameter defaultValue if the JSON object does not have such property.
Exceptions
`::tenduke::json::JSONException`if the property is not JSON number.

◆ getNumber()

xdjson::JSONNumber * tenduke::json::getNumber ( const tenduke::json::JSONObject object,
const std::string &  propertyName 
)

Helper to get JSON object property as tenduke::json::JSONNumber.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
Returns
The JSON object property as JSON number. Returns nullptr if the JSON object does not have such property or if the property is null or undefined.
Exceptions
`::tenduke::json::JSONException`if the property is not JSON number.

◆ getObject()

xdjson::JSONObject * tenduke::json::getObject ( const tenduke::json::JSONObject object,
const std::string &  propertyName 
)

Helper to get JSON object property as tenduke::json::JSONObject.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
Returns
The JSON object property as JSON object. Returns nullptr if the JSON object does not have such property or if the property is null or undefined.
Exceptions
`::tenduke::json::JSONException`if the property is not JSON object.

◆ getStdString() [1/2]

std::string tenduke::json::getStdString ( const tenduke::json::JSONObject object,
const std::string &  propertyName,
const std::string &  defaultValue = {} 
)

Helper to get JSON object property as std::string.

The property does not need to be tenduke::json::JSONString. This returns result of calling tenduke::json::JSONElement.asString() on the property element.

This function does not throw exceptions.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
defaultValuedefault value to return if no such property, or the property is null or undefined
Returns
Result of calling tenduke::json::JSONElement.asString() on the property element. Returns parameter defaultValue if the JSON object does not have such property or if the property is null or undefined.

◆ getStdString() [2/2]

std::string tenduke::json::getStdString ( const tenduke::json::JSONObject object,
const std::string &  propertyName,
const std::string &  defaultValue = {} 
)

Helper to get JSON object property as std::string.

The property does not need to be tenduke::json::JSONString. This returns result of calling tenduke::json::JSONElement.asString() on the property element.

This function does not throw exceptions.

Parameters
objectthe JSON object
propertyNamename of the JSON object property
defaultValuedefault value to return if no such property, or the property is null or undefined
Returns
Result of calling tenduke::json::JSONElement.asString() on the property element. Returns parameter defaultValue if the JSON object does not have such property or if the property is null or undefined.

◆ isBooleanTrue() [1/3]

bool tenduke::json::isBooleanTrue ( const JSONElement element)

Returns true if element is JSONBoolean with value true.

Parameters
element-
Returns
-

◆ isBooleanTrue() [2/3]

bool tenduke::json::isBooleanTrue ( const std::shared_ptr< const JSONElement > &  element)

Returns true if element is JSONBoolean with value true.

Parameters
element-
Returns
-

◆ isBooleanTrue() [3/3]

bool tenduke::json::isBooleanTrue ( const std::unique_ptr< const JSONElement > &  element)

Returns true if element is JSONBoolean with value true.

Parameters
element-
Returns
-

◆ toInt64() [1/2]

std::int64_t tenduke::json::toInt64 ( const JSONElement element,
bool  throwIfInvalid = true,
std::int64_t  defaultValue = 0 
)

Returns given element as std::int_64t, assuming the element is JSONNumber.

Parameters
element-
throwIfInvalidif true, the method throws tenduke::json::JSONException if the element is not JSONNumber. If false, returns parameter defaultValue if the element is e.g. nullptr or JSONString.
defaultValuedefault value to return if the provided element is not JSONNumber (or element is e.g. nullptr). See throwIfInvalid.
Returns
Exceptions
`::tenduke::json::JSONException`if the element is not JSON number and throwIfInvalid is true.

◆ toInt64() [2/2]

std::int64_t tenduke::json::toInt64 ( const JSONElement element,
bool  throwIfInvalid = true,
std::int64_t  defaultValue = 0 
)

Returns given element as std::int_64t, assuming the element is JSONNumber.

Parameters
element-
throwIfInvalidif true, the method throws tenduke::json::JSONException if the element is not JSONNumber. If false, returns parameter defaultValue if the element is e.g. nullptr or JSONString.
defaultValuedefault value to return if the provided element is not JSONNumber (or element is e.g. nullptr). See throwIfInvalid.
Returns
Exceptions
`::tenduke::json::JSONException`if the element is not JSON number and throwIfInvalid is true.

◆ toMapOfStrings()

std::map< std::string, std::string > tenduke::json::toMapOfStrings ( const tenduke::json::JSONObject object)

Converts a tenduke::json::JSONObject to a flattened map of strings, where the key is name of the object property and value is result of calling tenduke::json::JSONElement.asString() on the property element.

Parameters
objectthe JSON object
Returns
flattened map-representation of the JSON object