Maze Builder Docs 8.2.1
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
 

Static Public Member Functions

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.
 

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]

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
s
m
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_printNumber 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_printNumber 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
sJSON string containing an array of objects
vmVector 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
filename
m
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
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: