1
0
mirror of https://github.com/nlohmann/json synced 2024-11-15 00:31:05 +00:00
nlohmannjson/doc/examples/patch.cpp
2017-12-16 12:37:25 +01:00

32 lines
674 B
C++

#include <iostream>
#include "json.hpp"
using json = nlohmann::json;
int main()
{
// the original document
json doc = R"(
{
"baz": "qux",
"foo": "bar"
}
)"_json;
// the patch
json patch = R"(
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo"}
]
)"_json;
// apply the patch
json patched_doc = doc.patch(patch);
// output original and patched document
std::cout << std::setw(4) << doc << "\n\n"
<< std::setw(4) << patched_doc << std::endl;
}