• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <iostream>
2 #include <nlohmann/json.hpp>
3 #include <iomanip> // for std::setw
4 
5 using json = nlohmann::json;
6 using namespace nlohmann::literals;
7 
main()8 int main()
9 {
10     // the original document
11     json document = R"({
12                 "title": "Goodbye!",
13                 "author": {
14                     "givenName": "John",
15                     "familyName": "Doe"
16                 },
17                 "tags": [
18                     "example",
19                     "sample"
20                 ],
21                 "content": "This will be unchanged"
22             })"_json;
23 
24     // the patch
25     json patch = R"({
26                 "title": "Hello!",
27                 "phoneNumber": "+01-123-456-7890",
28                 "author": {
29                     "familyName": null
30                 },
31                 "tags": [
32                     "example"
33                 ]
34             })"_json;
35 
36     // apply the patch
37     document.merge_patch(patch);
38 
39     // output original and patched document
40     std::cout << std::setw(4) << document << std::endl;
41 }
42