-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve.cpp
52 lines (42 loc) · 1.42 KB
/
resolve.cpp
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
#include <minjsoncpp.h>
#include <iostream>
using namespace std::string_view_literals;
template<typename... T>
void printResolved(const minjson::Value &document, T &&...referenceTokens) {
const auto resolved = document.resolve(std::forward<T>(referenceTokens)...);
std::cout << (resolved ? "resolved value" : "resolution failed");
std::cout << " for \'";
((std::cout << '/' << referenceTokens), ...);
std::cout << '\'';
if (resolved) {
std::cout << ":\n\n";
minjson::serializeToStream(std::cout, *resolved);
std::cout << '\n';
}
std::cout << '\n';
}
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
std::cout << "JSON:\n\n" << minjson::serializeToString(value, { 2 }) << "\n\n";
printResolved(value, "array", 1);
printResolved(value, "object", "nested number");
printResolved(value, "object", "nested array", 0);
printResolved(value, "object", "nested object", "foo");
printResolved(value, "nonexistent");
}