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 source document 11 json source = R"( 12 { 13 "baz": "qux", 14 "foo": "bar" 15 } 16 )"_json; 17 18 // the target document 19 json target = R"( 20 { 21 "baz": "boo", 22 "hello": [ 23 "world" 24 ] 25 } 26 )"_json; 27 28 // create the patch 29 json patch = json::diff(source, target); 30 31 // roundtrip 32 json patched_source = source.patch(patch); 33 34 // output patch and roundtrip result 35 std::cout << std::setw(4) << patch << "\n\n" 36 << std::setw(4) << patched_source << std::endl; 37 } 38