operator_deserialize.cpp 524 B

1234567891011121314151617181920212223242526
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <sstream>
  4. #include <nlohmann/json.hpp>
  5. using json = nlohmann::json;
  6. int main()
  7. {
  8. // create stream with serialized JSON
  9. std::stringstream ss;
  10. ss << R"({
  11. "number": 23,
  12. "string": "Hello, world!",
  13. "array": [1, 2, 3, 4, 5],
  14. "boolean": false,
  15. "null": null
  16. })";
  17. // create JSON value and read the serialization from the stream
  18. json j;
  19. ss >> j;
  20. // serialize JSON
  21. std::cout << std::setw(2) << j << '\n';
  22. }