Eile Mit Weile
Loading...
Searching...
No Matches
json_utils.hpp
1// Helper functions for rapidjson elements
2
3#ifndef EILE_MIT_WEILE_JSON_UTILS_HPP
4#define EILE_MIT_WEILE_JSON_UTILS_HPP
5
6#include <string>
7
8#include "rapidjson/writer.h"
9#include "rapidjson/document.h"
10#include "rapidjson/stringbuffer.h"
11
18public:
19 static std::string ToString(const rapidjson::Value* json) {
20 rapidjson::StringBuffer buffer;
21 buffer.Clear();
22 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
23 json->Accept(writer);
24 return buffer.GetString();
25 }
26
27 // In case you need to create a rapidjson::Document on the heap (pointer) based on a value extracted from a json.
28 static rapidjson::Document* CloneValue(const rapidjson::Value& val) {
29 auto* state_json = new rapidjson::Document(rapidjson::kObjectType);
30 state_json->CopyFrom(val, state_json->GetAllocator());
31 return state_json;
32 }
33
34};
35#endif //EILE_MIT_WEILE_JSON_UTILS_HPP
Helper functions for rapidjson elements.
Definition json_utils.hpp:17
static rapidjson::Document * CloneValue(const rapidjson::Value &val)
Definition json_utils.hpp:28
static std::string ToString(const rapidjson::Value *json)
Definition json_utils.hpp:19