mirror of
https://github.com/nlohmann/json.git
synced 2024-11-28 17:39:02 +08:00
9b32f72584
As I learned in https://github.com/melpon/wandbox/issues/209, this library is already installed at Wandbox, so we need to adjust the examples to use `#include "json.hpp"` insteas of `#include <json.hpp>`.
32 lines
690 B
C++
32 lines
690 B
C++
#include "json.hpp"
|
|
#include <iomanip> // for std::setw
|
|
|
|
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;
|
|
}
|