1 #include <iostream>
2 #include <iomanip>
3 #include <nlohmann/json.hpp>
4
5 using json = nlohmann::json;
6
main()7 int main()
8 {
9 // a JSON text
10 auto text = R"(
11 {
12 "Image": {
13 "Width": 800,
14 "Height": 600,
15 "Title": "View from 15th Floor",
16 "Thumbnail": {
17 "Url": "http://www.example.com/image/481989943",
18 "Height": 125,
19 "Width": 100
20 },
21 "Animated" : false,
22 "IDs": [116, 943, 234, 38793]
23 }
24 }
25 )";
26
27 // parse and serialize JSON
28 json j_complete = json::parse(text);
29 std::cout << std::setw(4) << j_complete << "\n\n";
30
31 // define parser callback
32 json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
__anoned40023c0102(int depth, json::parse_event_t event, json & parsed) 33 {
34 // skip object elements with key "Thumbnail"
35 if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
36 {
37 return false;
38 }
39 else
40 {
41 return true;
42 }
43 };
44
45 // parse (with callback) and serialize JSON
46 json j_filtered = json::parse(text, cb);
47 std::cout << std::setw(4) << j_filtered << '\n';
48 }
49