23 lines
501 B
C++
23 lines
501 B
C++
|
#include <fmt/format.h>
|
||
|
#include <nlohmann/json.hpp>
|
||
|
#include <iostream>
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
nlohmann::json j;
|
||
|
j["pi"] = 3.141;
|
||
|
j["happy"] = true;
|
||
|
j["name"] = "Niels";
|
||
|
j["nothing"] = nullptr;
|
||
|
j["answer"]["everything"] = 42;
|
||
|
j["list"] = {1, 0, 2};
|
||
|
j["object"] = {{"currency", "USD"}, {"value", 42.99}};
|
||
|
|
||
|
std::string s = j.dump();
|
||
|
std::cout << s << std::endl;
|
||
|
|
||
|
nlohmann::json j2 = nlohmann::json::parse(s);
|
||
|
std::cout << j2.dump(4) << std::endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|