2017-07-09 12:51:38 +03:00
|
|
|
#include <iostream>
|
2018-08-16 22:53:47 +03:00
|
|
|
#include <iomanip>
|
2018-02-02 00:20:26 +03:00
|
|
|
#include <nlohmann/json.hpp>
|
2015-06-21 23:42:32 +03:00
|
|
|
|
2016-01-30 22:23:14 +03:00
|
|
|
using json = nlohmann::json;
|
2015-06-21 23:42:32 +03:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create JSON values
|
|
|
|
json j_object = {{"one", 1}, {"two", 2}};
|
|
|
|
json j_array = {1, 2, 4, 8, 16};
|
|
|
|
|
|
|
|
// serialize without indentation
|
|
|
|
std::cout << j_object << "\n\n";
|
|
|
|
std::cout << j_array << "\n\n";
|
|
|
|
|
|
|
|
// serialize with indentation
|
|
|
|
std::cout << std::setw(4) << j_object << "\n\n";
|
|
|
|
std::cout << std::setw(2) << j_array << "\n\n";
|
2017-05-07 20:27:40 +03:00
|
|
|
std::cout << std::setw(1) << std::setfill('\t') << j_object << "\n\n";
|
2015-06-21 23:42:32 +03:00
|
|
|
}
|