This module provides interface with JSON files. More...
Functions | |
bool | GC_namespace::file_JSON_to_GC (string const &file_name, GenericContainer &gc) |
bool | GC_namespace::JSON_to_GC (istream_type &stream, GenericContainer &gc) |
bool | GC_namespace::JSON_to_GC (string const &DATA, GenericContainer &gc) |
void | GC_namespace::GC_to_JSON (GenericContainer const &gc, std::string &res) |
void | GC_namespace::GC_to_JSON (GenericContainer const &gc, ostream_type &stream) |
This module provides interface with JSON files.
The GenericContainer (GC) module offers a flexible container for storing various data types such as booleans, integers, floating-point numbers, complex numbers, and strings. It also supports structured data types such as vectors and maps. The C++ interface allows for seamless interaction with the container, enabling users to perform operations like adding elements, retrieving data, and managing hierarchical structures.
This tutorial explains how to use the GenericContainer JSON interface for converting between JSON data and the GenericContainer object.
The GenericContainer is a flexible structure that can store various data types like booleans, integers, floating-point numbers, complex numbers, strings, vectors, and maps. The interface provides multiple ways to convert JSON files, streams, or strings into GenericContainer objects and vice versa.
There are several ways to load JSON data into a GenericContainer.
The file_JSON_to_GC function reads JSON data from a file and populates a GenericContainer. This is useful for handling configuration files or other data stored in JSON format.
Example:
The JSON_to_GC function allows loading JSON data from an input stream, such as a file stream or a string stream.
Example:
You can convert a JSON string directly into a GenericContainer using the JSON_to_GC function.
Example:
If you have multiple JSON strings in a vector, you can load them into a GenericContainer using the JSON_to_GC function.
Example:
You can also convert a GenericContainer back to JSON format.
The GC_to_JSON function converts the contents of a GenericContainer into a vector of JSON strings.
Example:
You can write the contents of a GenericContainer to an output stream (e.g., a file) in JSON format using the GC_to_JSON function.
Example:
|
inline |
Convert a JSON file to a GenericContainer.
This function reads JSON data from the provided input stream and populates the given GenericContainer with the parsed data.
[in] | file_name | Input file name containing JSON data. |
[out] | gc | The GenericContainer to be populated. |
|
inline |
Convert a GenericContainer to a JSON file stream.
This function converts the contents of the provided GenericContainer into JSON format and writes it to the specified output stream.
[in] | gc | The GenericContainer to convert. |
[out] | stream | Output stream to write the JSON data. |
|
inline |
Convert a GenericContainer to a JSON string.
This function converts the contents of the provided GenericContainer into JSON format and stores it in the specified string.
[in] | gc | The GenericContainer to convert. |
[out] | DATA | String to store the JSON encoded GenericContainer. |
|
inline |
Convert a JSON file stream to a GenericContainer.
This function reads JSON data from the provided input stream and populates the given GenericContainer with the parsed data.
[in] | stream | Input stream containing JSON data. |
[out] | gc | The GenericContainer to be populated. |
|
inline |
Convert a JSON string to a GenericContainer.
This function parses the given JSON string and populates the specified GenericContainer with the resulting data.
[in] | DATA | The JSON string to parse. |
[out] | gc | The GenericContainer to be populated. |