1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-16 18:41:53 +03:00

add patch_inplace function (#3581)

* add patch_inplace function to json class

* add documentation

* fix up docs
This commit is contained in:
Wolf Vollprecht
2022-07-21 16:27:59 +02:00
committed by GitHub
parent 4b6d3638ca
commit 09fb4819ff
6 changed files with 131 additions and 12 deletions

View File

@ -0,0 +1,34 @@
#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 << "After\n" << std::setw(4) << doc << std::endl;
}