SPT JSON API  1.0.0
Developed by Sans Pareil Technologies, Inc. (SPT)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
spt::json Namespace Reference

A simple JSON parser implementation. More...

Namespaces

 io
 Classes that deal with parsing and generating JSON data.
 

Classes

struct  Array
 Represents a JSON array value/document. More...
 
class  Boolean
 Represents the JSON true and false values. More...
 
struct  Json
 Base class that is used to represent JSON data in a polymorphous manner. More...
 
class  Null
 Represents a JSON null value. More...
 
class  Number
 Represents a JSON number value. More...
 
struct  Object
 Represents a JSON object value/document. More...
 
class  String
 Represents a JSON string value. More...
 
struct  Value
 Abstract base class that represents a valid JSON value. More...
 

Functions

template<>
std::string & Array::get< std::string > (std::size_t index)
 Specialised method for retrieving the string value stored in a spt::json::String instance. More...
 
template<>
const std::string & Array::get< std::string > (std::size_t index) const
 Constant version of specialised method for strings. More...
 
bool operator== (const Array &lhs, const Array &rhs)
 Compare two arrays for equality. More...
 
std::ostream & operator<< (std::ostream &stream, const Array &array)
 Write the array to the specified output stream. More...
 
std::string & operator+= (std::string &output, const Array &array)
 Write the array to the specified output string. More...
 
bool operator== (const Boolean &lhs, const Boolean &rhs)
 
std::ostream & operator<< (std::ostream &stream, const Boolean &value)
 
std::string & operator+= (std::string &output, const Boolean &value)
 
bool operator== (const Null &, const Null &)
 Compare two null values for equality. Always returns true. More...
 
std::ostream & operator<< (std::ostream &stream, const Null &)
 Append the null value representation to the stream. More...
 
std::string & operator+= (std::string &output, const Null &)
 Append the null value representation to the string. More...
 
bool operator== (const Number &lhs, const Number &rhs)
 
bool operator== (const Number &lhs, int64_t rhs)
 
bool operator== (const Number &lhs, double rhs)
 
bool operator< (const Number &lhs, const Number &rhs)
 
std::ostream & operator<< (std::ostream &stream, const Number &number)
 
std::string & operator+= (std::string &output, const Number &number)
 
template<>
std::string & Object::get< std::string > (const std::string &name)
 
template<>
const std::string & Object::get< std::string > (const std::string &name) const
 Constant version of specialised method for strings. More...
 
bool operator== (const Object &lhs, const Object &rhs)
 Compare two objects for equality. More...
 
std::ostream & operator<< (std::ostream &stream, const Object &object)
 Write the object to the specified output stream. More...
 
std::string & operator+= (std::string &output, const Object &object)
 Write the object to the specified output string. More...
 
bool operator== (const String &lhs, const String &rhs)
 
bool operator== (const String &lhs, const std::string &rhs)
 
bool operator< (const String &lhs, const String &rhs)
 
std::ostream & operator<< (std::ostream &stream, const String &str)
 
std::string & operator+= (std::string &output, const String &str)
 
std::ostream & operator<< (std::ostream &stream, const Value &value)
 Write the value to the specified output stream. More...
 
std::string & operator+= (std::string &output, const Value &value)
 Write the value to the specified output string. More...
 
bool operator== (const Value &lhs, const Value &rhs)
 Compare two values for equality. Default implementation performs a true comparison of the standard value type implementations provided by this API. More...
 
bool operator!= (const Value &lhs, const Value &rhs)
 Just the reverse of operator ==. More...
 

Detailed Description

A simple JSON parser implementation.

A simple API for producing and consuming JSON data.

Note: This implementation does not attempt to handle/translate Unicode characters (\uxxxx) in the data. We may add support for properly handling Unicode characters at a later date.

Function Documentation

template<>
std::string& spt::json::Array::get< std::string > ( std::size_t  index)

Specialised method for retrieving the string value stored in a spt::json::String instance.

Parameters
indexThe index of the value in the array.
Returns
The string value associated with the index.
Exceptions
std::bad_castIf the value at specified index is not of type spt::json::Value::Type::String.
template<>
const std::string& spt::json::Array::get< std::string > ( std::size_t  index) const
inline

Constant version of specialised method for strings.

template<>
std::string& spt::json::Object::get< std::string > ( const std::string &  name)

Specialised method for retrieving the string value stored in a spt::json::String instance.

Parameters
nameThe name to which the string value is mapped.
Returns
The string value associated with the index.
Exceptions
std::bad_castIf the mapping for specified name is not of type spt::json::Value::Type::String.
template<>
const std::string& spt::json::Object::get< std::string > ( const std::string &  name) const
inline

Constant version of specialised method for strings.

bool spt::json::operator!= ( const Value &  lhs,
const Value &  rhs 
)
inline

Just the reverse of operator ==.

std::string& spt::json::operator+= ( std::string &  output,
const Null &   
)
inline

Append the null value representation to the string.

std::string& spt::json::operator+= ( std::string &  output,
const Boolean &  value 
)
inline
std::string& spt::json::operator+= ( std::string &  output,
const String &  str 
)
std::string& spt::json::operator+= ( std::string &  output,
const Value &  value 
)

Write the value to the specified output string.

This is the easiest way of serialising a JSON value to an output string without introspecting its type.

Parameters
outputThe output string to append the value to
valueThe value to write to the string
std::string& spt::json::operator+= ( std::string &  output,
const Number &  number 
)
inline
std::string& spt::json::operator+= ( std::string &  output,
const Array &  array 
)

Write the array to the specified output string.

Parameters
outputThe output string to append the array to
arrayThe array to write to the string
std::string& spt::json::operator+= ( std::string &  output,
const Object &  object 
)

Write the object to the specified output string.

Parameters
outputThe output string to append the object to
valueThe value to write to the string
bool spt::json::operator< ( const String &  lhs,
const String &  rhs 
)
inline
bool spt::json::operator< ( const Number &  lhs,
const Number &  rhs 
)
inline
std::ostream& spt::json::operator<< ( std::ostream &  stream,
const Null &   
)
inline

Append the null value representation to the stream.

std::ostream& spt::json::operator<< ( std::ostream &  stream,
const Boolean &  value 
)
inline
std::ostream& spt::json::operator<< ( std::ostream &  stream,
const String &  str 
)
std::ostream& spt::json::operator<< ( std::ostream &  stream,
const Value &  value 
)

Write the value to the specified output stream.

This is the easiest way of serialising a JSON value to an output stream without introspecting its type.

Parameters
streamThe output stream to write the value to
valueThe value to write to the stream
std::ostream& spt::json::operator<< ( std::ostream &  stream,
const Number &  number 
)
inline
std::ostream& spt::json::operator<< ( std::ostream &  stream,
const Array &  array 
)

Write the array to the specified output stream.

Parameters
streamThe output stream to write the array to
arrayThe array to write to the stream
std::ostream& spt::json::operator<< ( std::ostream &  stream,
const Object &  object 
)

Write the object to the specified output stream.

Parameters
streamThe output stream to write the object to
objectThe object to write to the stream
bool spt::json::operator== ( const Null &  ,
const Null &   
)
inline

Compare two null values for equality. Always returns true.

bool spt::json::operator== ( const Boolean &  lhs,
const Boolean &  rhs 
)
inline
bool spt::json::operator== ( const String &  lhs,
const String &  rhs 
)
inline
bool spt::json::operator== ( const String &  lhs,
const std::string &  rhs 
)
inline
bool spt::json::operator== ( const Number &  lhs,
const Number &  rhs 
)
inline
bool spt::json::operator== ( const Number &  lhs,
int64_t  rhs 
)
inline
bool spt::json::operator== ( const Number &  lhs,
double  rhs 
)
inline
bool spt::json::operator== ( const Value &  lhs,
const Value &  rhs 
)

Compare two values for equality. Default implementation performs a true comparison of the standard value type implementations provided by this API.

Parameters
lhsThe left hand value to compare
rhsThe right hand value to compare
Returns
Return true if the two instances are the same.
bool spt::json::operator== ( const Array &  lhs,
const Array &  rhs 
)

Compare two arrays for equality.

Two arrays are equal if they have same size and equal values.

Parameters
lhsThe left hand array to compare
rhsThe right hand array to compare
Returns
Return true if the two instances are the same.
bool spt::json::operator== ( const Object &  lhs,
const Object &  rhs 
)

Compare two objects for equality.

Two objects are equal if they have same size and equal name/value pairs.

Parameters
lhsThe left hand object to compare
rhsThe right hand object to compare
Returns
Return true if the two instances are the same.