1 #include <iostream> 2 #include <nlohmann/json.hpp> 3 4 using json = nlohmann::json; 5 main()6int main() 7 { 8 // create JSON values 9 json object = {{"one", 1}, {"two", 2}}; 10 json null; 11 12 // print values 13 std::cout << object << '\n'; 14 std::cout << null << '\n'; 15 16 // add values: 17 object.push_back({"three", 3}); // object is extended 18 object += {"four", 4}; // object is extended 19 null.push_back({"five", 5}); // null is converted to array 20 21 // print values 22 std::cout << object << '\n'; 23 std::cout << null << '\n'; 24 25 // would throw: 26 //object.push_back({1, 2, 3}); 27 } 28