Maze Builder Docs 6.7.5
Loading...
Searching...
No Matches
mazes::json_helper Class Reference

JSON helper class. More...

#include <json_helper.h>

Public Member Functions

 json_helper ()
 Default constructor.
 
 ~json_helper ()
 Destructor.
 
 json_helper (const json_helper &other)
 
json_helperoperator= (const json_helper &other)
 
 json_helper (json_helper &&other) noexcept=default
 
json_helperoperator= (json_helper &&other) noexcept=default
 
std::string from (const std::unordered_map< std::string, std::string > &map, int pretty_print=4) const noexcept
 Get the contents of a map as a string in JSON format.
 
std::string from (const std::vector< std::unordered_map< std::string, std::string > > &arr, int pretty_print=4) const noexcept
 Get the contents of a vector of maps as a JSON string.
 
bool from (const std::string &s, std::unordered_map< std::string, std::string > &m) const noexcept
 Parse and set a JSON string into a C++ map.
 
bool load (const std::string &filename, std::unordered_map< std::string, std::string > &m) const noexcept
 Parse a JSON file into a C++ map from a file on disk.
 
bool from_array (const std::string &s, std::vector< std::unordered_map< std::string, std::string > > &vm) const noexcept
 Parse a JSON array string into a vector of maps.
 
bool load_array (const std::string &filename, std::vector< std::unordered_map< std::string, std::string > > &vm) const noexcept
 Load a JSON array file into a vector of maps.
 

Detailed Description

JSON helper class.

This class provides methods to convert a map of strings into a JSON string

Member Function Documentation

◆ from() [1/3]

bool mazes::json_helper::from ( const std::string & s,
std::unordered_map< std::string, std::string > & m ) const
noexcept

Parse and set a JSON string into a C++ map.

Parameters
s
m
Returns
success or failure on parse

◆ from() [2/3]

std::string mazes::json_helper::from ( const std::unordered_map< std::string, std::string > & map,
int pretty_print = 4 ) const
noexcept

Get the contents of a map as a string in JSON format.

Parameters
map
pretty_printNumber of spaces to use for indenting the JSON string
Returns

◆ from() [3/3]

std::string mazes::json_helper::from ( const std::vector< std::unordered_map< std::string, std::string > > & arr,
int pretty_print = 4 ) const
noexcept

Get the contents of a vector of maps as a JSON string.

Parameters
arr
pretty_printNumber of spaces to use for indenting the JSON string
Returns

◆ from_array()

bool mazes::json_helper::from_array ( const std::string & s,
std::vector< std::unordered_map< std::string, std::string > > & vm ) const
noexcept

Parse a JSON array string into a vector of maps.

Parameters
sJSON string containing an array of objects
vmVector of maps to populate with parsed objects
Returns
success or failure on parse

◆ load()

bool mazes::json_helper::load ( const std::string & filename,
std::unordered_map< std::string, std::string > & m ) const
noexcept

Parse a JSON file into a C++ map from a file on disk.

Parameters
filename
m
Returns

◆ load_array()

bool mazes::json_helper::load_array ( const std::string & filename,
std::vector< std::unordered_map< std::string, std::string > > & vm ) const
noexcept

Load a JSON array file into a vector of maps.

Parameters
filenamePath to JSON file containing an array of objects
vmVector 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: