1
0
mirror of https://github.com/nlohmann/json synced 2024-11-22 12:00:05 +00:00
nlohmannjson/docs/examples/push_back__initializer_list.cpp
Niels Lohmann b21c345179
Reorganize directories (#3462)
* 🚚 move files
* 🚚 rename doc folder to docs
* 🚚 rename test folder to tests
2022-05-01 09:41:50 +02:00

28 lines
611 B
C++

#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
// create JSON values
json object = {{"one", 1}, {"two", 2}};
json null;
// print values
std::cout << object << '\n';
std::cout << null << '\n';
// add values:
object.push_back({"three", 3}); // object is extended
object += {"four", 4}; // object is extended
null.push_back({"five", 5}); // null is converted to array
// print values
std::cout << object << '\n';
std::cout << null << '\n';
// would throw:
//object.push_back({1, 2, 3});
}