xref: /third_party/json/docs/examples/items.cpp (revision c5f01b2f)
1#include <iostream>
2#include <nlohmann/json.hpp>
3
4using json = nlohmann::json;
5
6int main()
7{
8    // create JSON values
9    json j_object = {{"one", 1}, {"two", 2}};
10    json j_array = {1, 2, 4, 8, 16};
11
12    // example for an object
13    for (auto& x : j_object.items())
14    {
15        std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
16    }
17
18    // example for an array
19    for (auto& x : j_array.items())
20    {
21        std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
22    }
23}
24