forked from Research/WhisperCom
Dominik Meyer
cc002ebfbb
git-subtree-dir: libs/json git-subtree-split: f42a74b8f53cc308647123d49d33d1c8122e3f42
33 lines
702 B
C++
33 lines
702 B
C++
#include <iostream>
|
|
#include <iomanip>
|
|
#include <nlohmann/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;
|
|
}
|