1 #include <iostream>
2 #include <nlohmann/json.hpp>
3 
4 using json = nlohmann::json;
5 using namespace nlohmann::literals;
6 
main()7 int main()
8 {
9     // create a JSON value
10     const json j =
11     {
12         {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
13     };
14 
15     // read-only access
16 
17     // output element with JSON pointer "/number"
18     std::cout << j["/number"_json_pointer] << '\n';
19     // output element with JSON pointer "/string"
20     std::cout << j["/string"_json_pointer] << '\n';
21     // output element with JSON pointer "/array"
22     std::cout << j["/array"_json_pointer] << '\n';
23     // output element with JSON pointer "/array/1"
24     std::cout << j["/array/1"_json_pointer] << '\n';
25 }
26