1 #include <iostream> 2 #include <iomanip> 3 #include <nlohmann/json.hpp> 4 5 using json = nlohmann::json; 6 main()7int main() 8 { 9 // the source document 10 json source = R"( 11 { 12 "baz": "qux", 13 "foo": "bar" 14 } 15 )"_json; 16 17 // the target document 18 json target = R"( 19 { 20 "baz": "boo", 21 "hello": [ 22 "world" 23 ] 24 } 25 )"_json; 26 27 // create the patch 28 json patch = json::diff(source, target); 29 30 // roundtrip 31 json patched_source = source.patch(patch); 32 33 // output patch and roundtrip result 34 std::cout << std::setw(4) << patch << "\n\n" 35 << std::setw(4) << patched_source << std::endl; 36 } 37