unflatten.cpp 553 B

1234567891011121314151617181920212223242526
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <nlohmann/json.hpp>
  4. using json = nlohmann::json;
  5. int main()
  6. {
  7. // create JSON value
  8. json j_flattened =
  9. {
  10. {"/answer/everything", 42},
  11. {"/happy", true},
  12. {"/list/0", 1},
  13. {"/list/1", 0},
  14. {"/list/2", 2},
  15. {"/name", "Niels"},
  16. {"/nothing", nullptr},
  17. {"/object/currency", "USD"},
  18. {"/object/value", 42.99},
  19. {"/pi", 3.141}
  20. };
  21. // call unflatten()
  22. std::cout << std::setw(4) << j_flattened.unflatten() << '\n';
  23. }