]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/doc/examples/object.cpp
2 #include <nlohmann/json.hpp>
4 using json
= nlohmann::json
;
9 json j_no_init_list
= json::object();
10 json j_empty_init_list
= json::object({});
11 json j_list_of_pairs
= json::object({ {"one", 1}, {"two", 2} });
13 // serialize the JSON objects
14 std::cout
<< j_no_init_list
<< '\n';
15 std::cout
<< j_empty_init_list
<< '\n';
16 std::cout
<< j_list_of_pairs
<< '\n';
18 // example for an exception
21 // can only create an object from a list of pairs
22 json j_invalid_object
= json::object({{ "one", 1, 2 }});
24 catch (json::type_error
& e
)
26 std::cout
<< e
.what() << '\n';