1 #include <iostream> 2 #include <iomanip> 3 #include <nlohmann/json.hpp> 4 5 using json = nlohmann::json; 6 main()7int main() 8 { 9 // create JSON values 10 json j_object = {{"one", 1}, {"two", 2}}; 11 json j_array = {1, 2, 4, 8, 16}; 12 13 // serialize without indentation 14 std::cout << j_object << "\n\n"; 15 std::cout << j_array << "\n\n"; 16 17 // serialize with indentation 18 std::cout << std::setw(4) << j_object << "\n\n"; 19 std::cout << std::setw(2) << j_array << "\n\n"; 20 std::cout << std::setw(1) << std::setfill('\t') << j_object << "\n\n"; 21 } 22