You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
657 B

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