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::io Namespace Reference

Classes that deal with parsing and generating JSON data. More...

Classes

class  DefaultHandler
 A default handler that populates a Json instance with the JSON data being parsed. More...
 
struct  Handler
 Streaming handler interface for parsing JSON data streams. More...
 
struct  Reader
 Base JSON data reader interface. Implementations provide support for reading JSON data from various sources. Event notifications will be sent to the callback handler set for the reader. Handler instances may be updated during the course of data parsing. More...
 
class  StreamReader
 JSON data parser for streams. More...
 
class  StreamWriter
 Writer for serialising spt::json::Json instances. More...
 
class  StringReader
 JSON data reader from strings. More...
 
class  StringWriter
 Writer for serialising spt::json::Json instances. More...
 
struct  Writer
 Base writer for serialising spt::json::Json instances. More...
 

Functions

Value::Ptr read (std::istream &stream)
 
Value::Ptr fromFile (const std::string &path)
 
Value::Ptr read (const std::string &json)
 
void toFile (const spt::json::Object &object, const std::string &filePath, bool prettyPrint=false, std::string decorator=std::string(" "))
 
void toFile (const spt::json::Array &array, const std::string &filePath, bool prettyPrint=false, std::string decorator=std::string(" "))
 

Detailed Description

Classes that deal with parsing and generating JSON data.

Function Documentation

Value::Ptr spt::json::io::fromFile ( const std::string &  path)
inline

Convenience function to read data from a file as the specified path into JSON object/array.

Parameters
pathThe path to the file to read.
Returns
Returns the unique_ptr to object/array.
Exceptions
std::runtime_errorIf JSON data is invalid.
Value::Ptr spt::json::io::read ( std::istream &  stream)

Convenience function to read data from the specified stream into JSON object/array.

Parameters
streamThe stream from which the JSON data will be read.
Returns
Returns the unique_ptr to object/array.
Exceptions
std::runtime_errorIf JSON data is invalid.
Value::Ptr spt::json::io::read ( const std::string &  json)

Convenience function to read data from the specified string into JSON object/array.

Parameters
jsonThe string from which the JSON data will be read.
Returns
Returns the unique_ptr to object/array.
Exceptions
std::runtime_errorIf JSON data is invalid.
void spt::json::io::toFile ( const spt::json::Object object,
const std::string &  filePath,
bool  prettyPrint = false,
std::string  decorator = std::string("  ") 
)

Write the specified JSON object to the specified file.

Parameters
objectThe JSON object to serialise
filePathThe path to the file to write the JSON data to.
prettyPrintIndicate whether output should be formatted for human readability.
decoratorThe formatting string to be used to format the output.
Exceptions
std::runtime_errorIf the file is not writable to.
void spt::json::io::toFile ( const spt::json::Array array,
const std::string &  filePath,
bool  prettyPrint = false,
std::string  decorator = std::string("  ") 
)

Write the specified JSON array to the specified file.

Parameters
arrayThe JSON array to serialise
filePathThe path to the file to write the JSON data to.
prettyPrintIndicate whether output should be formatted for human readability.
decoratorThe formatting string to be used to format the output.
Exceptions
std::runtime_errorIf the file is not writable to.