JSON helper class.
More...
#include <json_helper.h>
|
| static std::string | from (const std::unordered_map< std::string, std::string > &map, int pretty_print=4) noexcept |
| | Get the contents of a map as a string in JSON format.
|
| |
| static std::string | from (const std::vector< std::unordered_map< std::string, std::string > > &arr, int pretty_print=4) noexcept |
| | Get the contents of a vector of maps as a JSON string.
|
| |
| static bool | from (const std::string &s, std::unordered_map< std::string, std::string > &m) noexcept |
| | Parse and set a JSON string into a C++ map.
|
| |
| static bool | load (const std::string &filename, std::unordered_map< std::string, std::string > &m) noexcept |
| | Parse a JSON file into a C++ map from a file on disk.
|
| |
| static bool | from_array (const std::string &s, std::vector< std::unordered_map< std::string, std::string > > &vm) noexcept |
| | Parse a JSON array string into a vector of maps.
|
| |
| static bool | load_array (const std::string &filename, std::vector< std::unordered_map< std::string, std::string > > &vm) noexcept |
| | Load a JSON array file into a vector of maps.
|
| |
JSON helper class.
This class provides methods to convert a map of strings into a JSON string
◆ from() [1/3]
| static bool mazes::json_helper::from |
( |
const std::string & | s, |
|
|
std::unordered_map< std::string, std::string > & | m ) |
|
staticnoexcept |
Parse and set a JSON string into a C++ map.
- Parameters
-
- Returns
- success or failure on parse
◆ from() [2/3]
| static std::string mazes::json_helper::from |
( |
const std::unordered_map< std::string, std::string > & | map, |
|
|
int | pretty_print = 4 ) |
|
staticnoexcept |
Get the contents of a map as a string in JSON format.
- Parameters
-
| map | |
| pretty_print | Number of spaces to use for indenting the JSON string |
- Returns
- JSON string representation of the map
◆ from() [3/3]
| static std::string mazes::json_helper::from |
( |
const std::vector< std::unordered_map< std::string, std::string > > & | arr, |
|
|
int | pretty_print = 4 ) |
|
staticnoexcept |
Get the contents of a vector of maps as a JSON string.
- Parameters
-
| arr | |
| pretty_print | Number of spaces to use for indenting the JSON string |
- Returns
- JSON string representation of the vector of maps
◆ from_array()
| static bool mazes::json_helper::from_array |
( |
const std::string & | s, |
|
|
std::vector< std::unordered_map< std::string, std::string > > & | vm ) |
|
staticnoexcept |
Parse a JSON array string into a vector of maps.
- Parameters
-
| s | JSON string containing an array of objects |
| vm | Vector of maps to populate with parsed objects |
- Returns
- success or failure on parse
◆ load()
| static bool mazes::json_helper::load |
( |
const std::string & | filename, |
|
|
std::unordered_map< std::string, std::string > & | m ) |
|
staticnoexcept |
Parse a JSON file into a C++ map from a file on disk.
- Parameters
-
- Returns
◆ load_array()
| static bool mazes::json_helper::load_array |
( |
const std::string & | filename, |
|
|
std::vector< std::unordered_map< std::string, std::string > > & | vm ) |
|
staticnoexcept |
Load a JSON array file into a vector of maps.
- Parameters
-
| filename | Path to JSON file containing an array of objects |
| vm | Vector of maps to populate with parsed objects |
- Returns
- success or failure on load/parse
The documentation for this class was generated from the following file: