WhisperCom/doc/examples/operator_deserialize.cpp
Dominik Meyer cc002ebfbb Squashed 'libs/json/' content from commit f42a74b8
git-subtree-dir: libs/json
git-subtree-split: f42a74b8f53cc308647123d49d33d1c8122e3f42
2021-08-22 01:28:31 +02:00

27 lines
524 B
C++

#include <iostream>
#include <iomanip>
#include <sstream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create stream with serialized JSON
std::stringstream ss;
ss << R"({
"number": 23,
"string": "Hello, world!",
"array": [1, 2, 3, 4, 5],
"boolean": false,
"null": null
})";
// create JSON value and read the serialization from the stream
json j;
ss >> j;
// serialize JSON
std::cout << std::setw(2) << j << '\n';
}