6b6e554067
std::setw needs the iomanip header (at least with GCC).
20 lines
462 B
C++
20 lines
462 B
C++
#include <json.hpp>
|
|
#include <iomanip> // for std::setw
|
|
|
|
using json = nlohmann::json;
|
|
|
|
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";
|
|
}
|