mirror of
https://github.com/nlohmann/json.git
synced 2024-11-28 00:59:02 +08:00
9aafcbe965
* 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
38 lines
741 B
C++
38 lines
741 B
C++
#include <iostream>
|
|
#include <iomanip>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
using namespace nlohmann::literals;
|
|
|
|
int main()
|
|
{
|
|
// the source document
|
|
json source = R"(
|
|
{
|
|
"baz": "qux",
|
|
"foo": "bar"
|
|
}
|
|
)"_json;
|
|
|
|
// the target document
|
|
json target = R"(
|
|
{
|
|
"baz": "boo",
|
|
"hello": [
|
|
"world"
|
|
]
|
|
}
|
|
)"_json;
|
|
|
|
// create the patch
|
|
json patch = json::diff(source, target);
|
|
|
|
// roundtrip
|
|
json patched_source = source.patch(patch);
|
|
|
|
// output patch and roundtrip result
|
|
std::cout << std::setw(4) << patch << "\n\n"
|
|
<< std::setw(4) << patched_source << std::endl;
|
|
}
|