-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (40 loc) · 1.2 KB
/
main.cpp
File metadata and controls
54 lines (40 loc) · 1.2 KB
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
#include <iostream>
#include <cassert>
#include "JSON.h"
int main()
{
// define the json object
JSON json;
// json is an object
json = Object();
// json["a"] is an array
json["a"] = Array();
// assigning a value into the array
json["a"][0] = false;
// more options
{
json["a"][2] = "hello, world!"; // this resize the array to 3
assert(json["a"][1].isNull()); // not initialized elements are null
json["a"][1] = Object();
json["a"][1]["b"] = "c"; // string are accepted
json["a"][1]["d"] = 4; // integers are accepted
json["a"][1]["e"] = true; // booleans are accepted
json["b"] = "d";
}
// range based for-loop are accepted for Arrays and Objects
int i = 0;
for (JSON part : json["a"].get<Array>())
std::cout << "Element number " << i++ << " of json[\"a\"] is : " << part.strigify() << std::endl;
// print the json data in one line
std::cout << json.strigify() << std::endl;
// preaty print of json data
// equals to : cout << json.strigify(true) << endl;
std::cout << json << std::endl;
JSON json2;
// reading the json data from the input
// equals to : json2 = readJSON(cin);
std::cin >> json2;
// print the json input
std::cout << json2 << std::endl;
return 0;
}