xref: /third_party/json/docs/examples/array.cpp (revision c5f01b2f)
1#include <iostream>
2#include <nlohmann/json.hpp>
3
4using json = nlohmann::json;
5
6int main()
7{
8    // create JSON arrays
9    json j_no_init_list = json::array();
10    json j_empty_init_list = json::array({});
11    json j_nonempty_init_list = json::array({1, 2, 3, 4});
12    json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} });
13
14    // serialize the JSON arrays
15    std::cout << j_no_init_list << '\n';
16    std::cout << j_empty_init_list << '\n';
17    std::cout << j_nonempty_init_list << '\n';
18    std::cout << j_list_of_pairs << '\n';
19}
20