Files
json/examples/flatten__empty.cpp
T
2026-10-03 05:43:12 +00:00

24 lines
553 B
C++

#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create a JSON value with an empty object and an empty array
json j =
{
{"empty_object", json::object()},
{"empty_array", json::array()},
{"name", "Niels"}
};
// call flatten()
json flattened = j.flatten();
std::cout << std::setw(4) << flattened << "\n\n";
// the empty containers cannot be restored by unflatten()
std::cout << std::setw(4) << flattened.unflatten() << '\n';
}