json/docs/examples/patch_inplace.cpp
Niels Lohmann d1d79b930d
Adjust JSON Pointer examples (#3622)
* 📝 adjust JSON Pointer examples

* 👷 add test for documentation

* 📝 note platform-dependent output on some examples
2022-07-29 14:28:37 +02:00

35 lines
736 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;
// output original document
std::cout << "Before\n" << std::setw(4) << doc << std::endl;
// apply the patch
doc.patch_inplace(patch);
// output patched document
std::cout << "\nAfter\n" << std::setw(4) << doc << std::endl;
}