]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/doc/examples/basic_json__value_ptr.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / nlohmann-json / doc / examples / basic_json__value_ptr.cpp
1 #include <iostream>
2 #include <nlohmann/json.hpp>
3
4 using json = nlohmann::json;
5
6 int main()
7 {
8 // create a JSON object with different entry types
9 json j =
10 {
11 {"integer", 1},
12 {"floating", 42.23},
13 {"string", "hello world"},
14 {"boolean", true},
15 {"object", {{"key1", 1}, {"key2", 2}}},
16 {"array", {1, 2, 3}}
17 };
18
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);
22
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);
26
27 // output values
28 std::cout << std::boolalpha << v_integer << " " << v_floating
29 << " " << v_string << " " << v_boolean << "\n";
30 }