operatorarray__key_type.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 object
00008     json object =
00009     {
00010         {"one", 1}, {"two", 2}, {"three", 2.9}
00011     };
00012 
00013     // output element with key "two"
00014     std::cout << object["two"] << "\n\n";
00015 
00016     // change element with key "three"
00017     object["three"] = 3;
00018 
00019     // output changed array
00020     std::cout << std::setw(4) << object << "\n\n";
00021 
00022     // mention nonexisting key
00023     object["four"];
00024 
00025     // write to nonexisting key
00026     object["five"]["really"]["nested"] = true;
00027 
00028     // output changed object
00029     std::cout << std::setw(4) << object << '\n';
00030 }


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