-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.hpp
49 lines (39 loc) · 1.76 KB
/
json.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*! @file */
#ifndef JSON_HPP
#define JSON_HPP
#include "jsoncpp/json.h"
#include <string>
#include <vector>
//!Typedef'd in-case JSON library is ever changed.
typedef Json::Value json_t;
/**Converts a json_t to a std::string (same as the std::to_string function).
\param json JSON object to convert.
\return String representation of JSON object.
*/
std::string JSON_serialize(const json_t& json);
/**Converts a std::string represented JSON object into a json_t (throws on bad JSON string).
\param stringified String representation of JSON object.
\return JSON object of the passed string.
*/
json_t JSON_parse(const std::string& stringified);
/**Converts a json_t to a std::string (same as the std::string JSON_serialize function).
\param json JSON object to convert.
\return String representation of JSON object.
*/
std::string to_string(const json_t& json);
/**Converts a JSON array object containing doubles or ints to a C++ vector of doubles (throws if json array contains values other than doubles or ints).
\param json JSON object to convert.
\return Vector of doubles.
*/
std::vector<double> to_double_array(const json_t& json);
/**Converts a JSON array object containing unsigned ints to a C++ vector of size_t (throws if json array contains values other than ints >= 0).
\param json JSON object to convert.
\return Vector of size_t.
*/
std::vector<size_t> to_size_array(const json_t& json);
/**Converts a JSON array object containing JSON array objects of doubles or ints to a C++ vector of vector of doubles (throws if json array contains values that contain values other than doubles or ints).
\param json JSON object to convert.
\return Vector of vector of doubles.
*/
std::vector<std::vector<double>> to_array_double_array(const json_t& json);
#endif