rili::JSON Class Referencefinal

Classes

class  SyntaxError
 

Public Types

enum  Type {
  Null, Boolean, String, Number,
  Array, Object
}
 
typedef std::list< JSONArrayType
 
typedef std::list< std::pair< std::string, JSON > > ObjectType
 

Public Member Functions

Type type () const noexcept
 
bool & boolean ()
 
std::string & string ()
 
std::string & number ()
 
ArrayTypearray ()
 
ObjectTypeobject ()
 
bool const & boolean () const
 
std::string const & string () const
 
std::string const & number () const
 
ArrayType const & array () const
 
ObjectType const & object () const
 
void null ()
 
void boolean (bool b)
 
void string (std::string const &s)
 
void number (std::string const &n)
 
void array (ArrayType const &a)
 
void object (ObjectType const &o)
 
 JSON () noexcept
 
 JSON (std::string const &json, size_t maxDepth=100)
 
void parse (const std::string &json, size_t maxDepth=100)
 
std::string stringify () const noexcept
 

Detailed Description

Note
Number value is internally stored and parsed exactly the same like in original JSON string. Parser only validate it against JSON requirements, as there is not precisely specified range, precision and other parameters of Number value in JSON standards. Because of that we belive it's better to not force any C++ POD(double, int etc.) or data structure(GMP BigNumbers) here - you will probably better know how to convert these numbers or meybe you even don't need this conversion at all.
Warning
You should ensure that data that you are assigning as Number is in valid JSON number format.
Note
String JSON value and Object JSON value keys are parsed as utf-8 encoded string
Warning
You should ensure that data that you are assigning as String or Object key is valid utf-8 encoded.

Member Typedef Documentation

typedef std::list<JSON> rili::JSON::ArrayType

ArrayType is type used to store json Arrays.

typedef std::list<std::pair<std::string, JSON> > rili::JSON::ObjectType

ObjectType is type used to store json Objects.

Member Enumeration Documentation

enum rili::JSON::Type
strong

The Type enum used to deduce specialized type of JSON node.

Constructor & Destructor Documentation

rili::JSON::JSON ( )
inlinenoexcept

Value default constructor initializes Value as.

rili::JSON::JSON ( std::string const &  json,
size_t  maxDepth = 100 
)
inline

JSON constructs root node from json string.

Parameters
jsoninput JSON formated utf-8 encoded string
maxDepthspecify how deep nasted Objects/Arrays will be accepted

Member Function Documentation

ArrayType& rili::JSON::array ( )
inline

array retrieve internaly stored value of array type

Warning
throw std::bad_cast if type not match to really used
Returns
value
ArrayType const& rili::JSON::array ( ) const
inline

array retrieve internaly stored value of array type

Warning
throw std::bad_cast if type not match to really used
Returns
value
void rili::JSON::array ( ArrayType const &  a)
inline

array assign array value to current JSON object

Parameters
avalue to assign
bool& rili::JSON::boolean ( )
inline

boolean retrieve internaly stored value of boolean type

Warning
throw std::bad_cast if type not match to really used
Returns
value
bool const& rili::JSON::boolean ( ) const
inline

boolean retrieve internaly stored value of boolean type

Warning
throw std::bad_cast if type not match to really used
Returns
value
void rili::JSON::boolean ( bool  b)
inline

boolean assign bool value to current JSON object

Parameters
bvalue to assign
void rili::JSON::null ( )
inline

null assign null value to current JSON object

std::string& rili::JSON::number ( )
inline

number retrieve internaly stored value of number type

Warning
throw std::bad_cast if type not match to really used
Returns
value
std::string const& rili::JSON::number ( ) const
inline

number retrieve internaly stored value of number type

Warning
throw std::bad_cast if type not match to really used
Returns
value
void rili::JSON::number ( std::string const &  n)
inline

number assign number value to current JSON object

Parameters
nvalue to assign
ObjectType& rili::JSON::object ( )
inline

object retrieve internaly stored value of object type

Warning
throw std::bad_cast if type not match to really used
Returns
value
ObjectType const& rili::JSON::object ( ) const
inline

object retrieve internaly stored value of object type

Warning
throw std::bad_cast if type not match to really used
Returns
value
void rili::JSON::object ( ObjectType const &  o)
inline

object assign object value to current JSON object

Parameters
ovalue to assign
void rili::JSON::parse ( const std::string &  json,
size_t  maxDepth = 100 
)

parse is function used to covert JSON string to object tree representation

Parameters
jsoninput JSON formated utf-8 encoded string
maxDepthspecify how deep nasted Objects/Arrays will be accepted
std::string& rili::JSON::string ( )
inline

string retrieve internaly stored value of string type

Warning
throw std::bad_cast if type not match to really used
Returns
value
std::string const& rili::JSON::string ( ) const
inline

string retrieve internaly stored value of string type

Warning
throw std::bad_cast if type not match to really used
Returns
value
void rili::JSON::string ( std::string const &  s)
inline

string assign string value to current JSON object

Parameters
svalue to assign
std::string rili::JSON::stringify ( ) const
noexcept

stringify is function used to convert object tree structure into JSON string

Returns
utf-8 encoded JSON string
Type rili::JSON::type ( ) const
inlinenoexcept

type used to retrieve used specialized type of JSON node

Returns
node type

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