summaryrefslogtreecommitdiffstats
path: root/src/JsonUtils.cpp
blob: 2c6c8efbce9be0b669f52567c0bcd4c277ddd90b (plain) (blame)
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
50
51
52
53
54
55
#include "Globals.h"

#include "JsonUtils.h"
#include "json/json.h"

#include <sstream>


namespace JsonUtils
{

AString WriteFastString(const Json::Value & a_Root)
{
	Json::StreamWriterBuilder Builder;
	Builder["commentStyle"] = "None";
	Builder["indentation"] = "";
	return Json::writeString(Builder, a_Root);
}





AString WriteStyledString(const Json::Value & a_Root)
{
	Json::StreamWriterBuilder Builder;
	return Json::writeString(Builder, a_Root);
}





bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_ErrorMsg)
{
	Json::CharReaderBuilder Builder;
	std::unique_ptr<Json::CharReader> Reader(Builder.newCharReader());

	const char * Doc = a_JsonStr.data();
	return Reader->parse(Doc, Doc + a_JsonStr.size(), &a_Root, a_ErrorMsg);
}





AString SerializeSingleValueJsonObject(
	const AString & a_Key, const AString & a_Value)
{
	Json::Value root;
	root[a_Key] = a_Value;
	return JsonUtils::WriteFastString(root);
}

}  // namespace JsonUtils