2
0

basic_json__list_init_t.cpp 593 B

123456789101112131415161718192021
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create JSON values
  7. json j_empty_init_list = json({});
  8. json j_object = { {"one", 1}, {"two", 2} };
  9. json j_array = {1, 2, 3, 4};
  10. json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
  11. json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
  12. // serialize the JSON value
  13. std::cout << j_empty_init_list << '\n';
  14. std::cout << j_object << '\n';
  15. std::cout << j_array << '\n';
  16. std::cout << j_nested_object << '\n';
  17. std::cout << j_nested_array << '\n';
  18. }