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.

30 lines
654 B

  1. #include <json.hpp>
  2. using json = nlohmann::json;
  3. int main()
  4. {
  5. // the original document
  6. json doc = R"(
  7. {
  8. "baz": "qux",
  9. "foo": "bar"
  10. }
  11. )"_json;
  12. // the patch
  13. json patch = R"(
  14. [
  15. { "op": "replace", "path": "/baz", "value": "boo" },
  16. { "op": "add", "path": "/hello", "value": ["world"] },
  17. { "op": "remove", "path": "/foo"}
  18. ]
  19. )"_json;
  20. // apply the patch
  21. json patched_doc = doc.patch(patch);
  22. // output original and patched document
  23. std::cout << std::setw(4) << doc << "\n\n"
  24. << std::setw(4) << patched_doc << std::endl;
  25. }