-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserialize.cpp
More file actions
33 lines (27 loc) · 879 Bytes
/
Copy pathserialize.cpp
File metadata and controls
33 lines (27 loc) · 879 Bytes
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
#include <minjsoncpp.h>
#include <iostream>
using namespace std::string_view_literals;
int main() {
// clang-format off
const minjson::Value value = minjson::Object {
{ "null", minjson::Null{} },
{ "boolean", true },
{ "integer", 42 },
{ "decimal", 3.14 },
{ "string", "hello there"sv },
{ "array", minjson::Array{ 1, 2, 3 } },
{ "object", minjson::Object{
{ "nested number", 23 },
{ "nested string", "General Kenobi"sv },
{ "nested array", minjson::Array{ 4, 5, 6 } },
{ "nested object", minjson::Object{ { "foo", "bar"sv } } }
}
}
};
// clang-format on
minjson::SerializationOptions options;
options.indent = 2;
options.objectKeyValueSeparator = ": "sv;
const auto serialized = minjson::serializeToString(value, options);
std::cout << "serialized JSON:\n\n" << serialized << '\n';
}