• 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 
main()7 int main()
8 {
9     // the original document
10     json document = R"({
11                 "title": "Goodbye!",
12                 "author": {
13                     "givenName": "John",
14                     "familyName": "Doe"
15                 },
16                 "tags": [
17                     "example",
18                     "sample"
19                 ],
20                 "content": "This will be unchanged"
21             })"_json;
22 
23     // the patch
24     json patch = R"({
25                 "title": "Hello!",
26                 "phoneNumber": "+01-123-456-7890",
27                 "author": {
28                     "familyName": null
29                 },
30                 "tags": [
31                     "example"
32                 ]
33             })"_json;
34 
35     // apply the patch
36     document.merge_patch(patch);
37 
38     // output original and patched document
39     std::cout << std::setw(4) << document << std::endl;
40 }
41