mirror of
https://github.com/nlohmann/json.git
synced 2024-08-21 20:42:29 +02:00
* Move UDLs into nlohmann::literals::json_literals namespace * Add 'using namespace' to unit tests * Add 'using namespace' to examples * Add 'using namespace' to README * Move UDL mkdocs pages out of basic_json/ * Update documentation * Update docset index * Add JSON_GlobalUDLs CMake option * Add unit test * Build examples without global UDLs * Add CI target
36 lines
772 B
C++
36 lines
772 B
C++
#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;
|
|
}
|