]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/doc/examples/basic_json__value_ptr.cpp
2 #include <nlohmann/json.hpp>
4 using json
= nlohmann::json
;
8 // create a JSON object with different entry types
13 {"string", "hello world"},
15 {"object", {{"key1", 1}, {"key2", 2}}},
19 // access existing values
20 int v_integer
= j
.value("/integer"_json_pointer
, 0);
21 double v_floating
= j
.value("/floating"_json_pointer
, 47.11);
23 // access nonexisting values and rely on default value
24 std::string v_string
= j
.value("/nonexisting"_json_pointer
, "oops");
25 bool v_boolean
= j
.value("/nonexisting"_json_pointer
, false);
28 std::cout
<< std::boolalpha
<< v_integer
<< " " << v_floating
29 << " " << v_string
<< " " << v_boolean
<< "\n";