cleanup, test, and diff
This commit is contained in:
parent
96cfe7463f
commit
5e0bf75d60
10 changed files with 2068 additions and 716 deletions
30
doc/examples/patch.cpp
Normal file
30
doc/examples/patch.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue