mirror of
https://github.com/nlohmann/json.git
synced 2026-10-27 08:18:55 +00:00
Clean up and document project files (#4560)
This commit is contained in:
1 parent
ad2ee18539
commit
26cfec34be
519 files changed
+3301
-1332
No files matched your search
@@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
using namespace nlohmann::literals;
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user