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