Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::property_tree::json_parser Namespace Reference

Functions

template<class Ptree >
void read_json (std::basic_istream< typename Ptree::key_type::value_type > &stream, Ptree &pt)
 Read JSON from a the given stream and translate it to a property tree. More...
 
template<class Ptree >
void read_json (const std::string &filename, Ptree &pt, const std::locale &loc=std::locale())
 Read JSON from a the given file and translate it to a property tree. More...
 
template<class Ptree >
void write_json (std::basic_ostream< typename Ptree::key_type::value_type > &stream, const Ptree &pt, bool pretty=true)
 Translates the property tree to JSON and writes it the given output stream. More...
 
template<class Ptree >
void write_json (const std::string &filename, const Ptree &pt, const std::locale &loc=std::locale(), bool pretty=true)
 Translates the property tree to JSON and writes it the given file. More...
 

Function Documentation

template<class Ptree >
void boost::property_tree::json_parser::read_json ( std::basic_istream< typename Ptree::key_type::value_type > &  stream,
Ptree &  pt 
)

Read JSON from a the given stream and translate it to a property tree.

Note
Clears existing contents of property tree. In case of error the property tree unmodified.
Items of JSON arrays are translated into ptree keys with empty names. Members of objects are translated into named keys.
JSON data can be a string, a numeric value, or one of literals "null", "true" and "false". During parse, any of the above is copied verbatim into ptree data string.
Exceptions
json_parser_errorIn case of error deserializing the property tree.
Parameters
streamStream from which to read in the property tree.
[out]ptThe property tree to populate.

References boost::expressions::stream.

template<class Ptree >
void boost::property_tree::json_parser::read_json ( const std::string &  filename,
Ptree &  pt,
const std::locale &  loc = std::locale() 
)

Read JSON from a the given file and translate it to a property tree.

Note
Clears existing contents of property tree. In case of error the property tree unmodified.
Items of JSON arrays are translated into ptree keys with empty names. Members of objects are translated into named keys.
JSON data can be a string, a numeric value, or one of literals "null", "true" and "false". During parse, any of the above is copied verbatim into ptree data string.
Exceptions
json_parser_errorIn case of error deserializing the property tree.
Parameters
filenameName of file from which to read in the property tree.
[out]ptThe property tree to populate.
locThe locale to use when reading in the file contents.

References BOOST_PROPERTY_TREE_THROW, and boost::expressions::stream.

template<class Ptree >
void boost::property_tree::json_parser::write_json ( std::basic_ostream< typename Ptree::key_type::value_type > &  stream,
const Ptree &  pt,
bool  pretty = true 
)

Translates the property tree to JSON and writes it the given output stream.

Note
Any property tree key containing only unnamed subkeys will be rendered as JSON arrays.
Precondition
pt cannot contain keys that have both subkeys and non-empty data.
Exceptions
json_parser_errorIn case of error translating the property tree to JSON or writing to the output stream.
Parameters
streamThe stream to which to write the JSON representation of the property tree.
ptThe property tree to tranlsate to JSON and output.
prettyWhether to pretty-print. Defaults to true for backward compatibility.

References boost::expressions::stream.

template<class Ptree >
void boost::property_tree::json_parser::write_json ( const std::string &  filename,
const Ptree &  pt,
const std::locale &  loc = std::locale(),
bool  pretty = true 
)

Translates the property tree to JSON and writes it the given file.

Note
Any property tree key containing only unnamed subkeys will be rendered as JSON arrays.
Precondition
pt cannot contain keys that have both subkeys and non-empty data.
Exceptions
json_parser_errorIn case of error translating the property tree to JSON or writing to the file.
Parameters
filenameThe name of the file to which to write the JSON representation of the property tree.
ptThe property tree to translate to JSON and output.
locThe locale to use when writing out to the output file.
prettyWhether to pretty-print. Defaults to true and last place for backward compatibility.

References BOOST_PROPERTY_TREE_THROW, and boost::expressions::stream.