• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <iostream>
2 #include <iomanip>
3 #include <nlohmann/json.hpp>
4 
5 using json = nlohmann::json;
6 using namespace nlohmann::literals;
7 
main()8 int main()
9 {
10     // the original document
11     json doc = R"(
12         {
13           "baz": "qux",
14           "foo": "bar"
15         }
16     )"_json;
17 
18     // the patch
19     json patch = R"(
20         [
21           { "op": "replace", "path": "/baz", "value": "boo" },
22           { "op": "add", "path": "/hello", "value": ["world"] },
23           { "op": "remove", "path": "/foo"}
24         ]
25     )"_json;
26 
27     // output original document
28     std::cout << "Before\n" << std::setw(4) << doc << std::endl;
29 
30     // apply the patch
31     doc.patch_inplace(patch);
32 
33     // output patched document
34     std::cout << "\nAfter\n" << std::setw(4) << doc << std::endl;
35 }
36