1 #include <iostream> 2 #include <iomanip> 3 #include <nlohmann/json.hpp> 4 5 using json = nlohmann::json; 6 using namespace nlohmann::literals; 7 main()8int 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 // apply the patch 28 json patched_doc = doc.patch(patch); 29 30 // output original and patched document 31 std::cout << std::setw(4) << doc << "\n\n" 32 << std::setw(4) << patched_doc << std::endl; 33 } 34