operatorjson_pointer.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 
00003 using json = nlohmann::json;
00004 
00005 int main()
00006 {
00007     // create a JSON value
00008     json j =
00009     {
00010         {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
00011     };
00012 
00013     // read-only access
00014 
00015     // output element with JSON pointer "/number"
00016     std::cout << j["/number"_json_pointer] << '\n';
00017     // output element with JSON pointer "/string"
00018     std::cout << j["/string"_json_pointer] << '\n';
00019     // output element with JSON pointer "/array"
00020     std::cout << j["/array"_json_pointer] << '\n';
00021     // output element with JSON pointer "/array/1"
00022     std::cout << j["/array/1"_json_pointer] << '\n';
00023 
00024     // writing access
00025 
00026     // change the string
00027     j["/string"_json_pointer] = "bar";
00028     // output the changed string
00029     std::cout << j["string"] << '\n';
00030 
00031     // "change" a nonexisting object entry
00032     j["/boolean"_json_pointer] = true;
00033     // output the changed object
00034     std::cout << j << '\n';
00035 
00036     // change an array element
00037     j["/array/1"_json_pointer] = 21;
00038     // "change" an array element with nonexisting index
00039     j["/array/4"_json_pointer] = 44;
00040     // output the changed array
00041     std::cout << j["array"] << '\n';
00042 
00043     // "change" the arry element past the end
00044     j["/array/-"_json_pointer] = 55;
00045     // output the changed array
00046     std::cout << j["array"] << '\n';
00047 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05