• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <iostream>
2 #include <nlohmann/json.hpp>
3 
4 using json = nlohmann::json;
5 
main()6 int main()
7 {
8     // create JSON values
9     json object = {{"one", 1}, {"two", 2}};
10     json null;
11 
12     // print values
13     std::cout << object << '\n';
14     std::cout << null << '\n';
15 
16     // add values
17     auto res1 = object.emplace("three", 3);
18     null.emplace("A", "a");
19     null.emplace("B", "b");
20 
21     // the following call will not add an object, because there is already
22     // a value stored at key "B"
23     auto res2 = null.emplace("B", "c");
24 
25     // print values
26     std::cout << object << '\n';
27     std::cout << *res1.first << " " << std::boolalpha << res1.second << '\n';
28 
29     std::cout << null << '\n';
30     std::cout << *res2.first << " " << std::boolalpha << res2.second << '\n';
31 }
32