MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / apply_json_merge_patch

Function apply_json_merge_patch

examples/src/json_merge_patch_examples.cpp:12–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10namespace mergepatch = jsoncons::mergepatch;
11
12void apply_json_merge_patch()
13{
14 // Apply a JSON Patch
15
16 json doc = json::parse(R"(
17{
18 "title": "Goodbye!",
19 "author" : {
20 "givenName" : "John",
21 "familyName" : "Doe"
22 },
23 "tags":[ "example", "sample" ],
24 "content": "This will be unchanged"
25}
26 )");
27
28 json doc2 = doc;
29
30 json patch = json::parse(R"(
31{
32 "title": "Hello!",
33 "phoneNumber": "+01-123-456-7890",
34 "author": {
35 "familyName": null
36 },
37 "tags": [ "example" ]
38}
39 )");
40
41 mergepatch::apply_merge_patch(doc, patch);
42
43 std::cout << "(1)\n" << pretty_print(doc) << '\n';
44
45 // Create a JSON Patch
46
47 auto patch2 = mergepatch::from_diff(doc2,doc);
48
49 std::cout << "(2)\n" << pretty_print(patch2) << '\n';
50
51 mergepatch::apply_merge_patch(doc2,patch2);
52
53 std::cout << "(3)\n" << pretty_print(doc2) << '\n';
54}
55
56void create_json_merge_patch()
57{

Callers 1

mainFunction · 0.85

Calls 4

parseFunction · 0.85
apply_merge_patchFunction · 0.85
pretty_printFunction · 0.85
from_diffFunction · 0.50

Tested by

no test coverage detected