Lines Matching full:json
2 // __| | __| | | | JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
15 #include <nlohmann/json.hpp>
16 using nlohmann::json;
120 static void to_json(nlohmann::json& j, const address& a)
125 static void to_json(nlohmann::json& j, const contact& c)
127 j = json{{"person", c.m_person}, {"address", c.m_address}};
130 static void to_json(nlohmann::json& j, const contact_book& cb)
132 j = json{{"name", cb.m_book_name}, {"contacts", cb.m_contacts}};
208 static void from_json(const nlohmann::json& j, address& a)
213 static void from_json(const nlohmann::json& j, contact& c)
219 static void from_json(const nlohmann::json& j, contact_book& cb)
242 SECTION("conversion to json via free-functions")
244 CHECK(json(a) == json(23));
245 CHECK(json(n) == json("theo"));
246 CHECK(json(c) == json("France"));
247 CHECK(json(sfinae_addict) == R"({"name":"theo", "age":23, "country":"France"})"_json);
248 CHECK(json("Paris") == json(addr));
249 CHECK(json(cpp_programmer) ==
253 json(book) ==
258 SECTION("conversion from json via free-functions")
293 json person_json = big_json["contacts"][0]["person"];
344 static void to_json(json& j, const std::shared_ptr<T>& opt)
356 static void from_json(const json& j, std::shared_ptr<T>& opt)
372 static void to_json(json& j, const udt::legacy_type& l)
377 static void from_json(const json& j, udt::legacy_type& l)
392 json j = optPerson;
405 json j = person;
423 json j = lt;
429 json j = 4242;
442 static void to_json(json& j, const type& /*type*/)
447 static void from_json(const json& /*unnamed*/, type& opt)
453 static type from_json(const json& /*unnamed*/)
462 json j = std::vector<float> {1.0, 2.0, 3.0};
474 static void to_json(json& j, const std::unique_ptr<T>& opt)
487 static std::unique_ptr<T> from_json(const json& j)
505 json j = optPerson;
518 json j = person;
565 // In short, constructing a json by constructor calls to_json
684 json j = me;
697 json j;
704 json j = true;
711 json j(json::value_t::discarded);
719 json j = {1, 2, 3};
726 json j = 42;
733 json j = 42.0;
740 json j = 42u;
747 json j = "forty-two";
754 json j = json::binary({1, 2, 3}, 42);
764 json j = {{"forty", "two"}};
772 json j = 42;
789 struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
794 static_assert(!is_constructible_patched<json, incomplete>::value, "");
812 void from_json(const json& /*unused*/, Evil& /*unused*/) {}
818 auto j = json::array();
831 static_assert(!std::is_convertible<json, non_convertible_type>::value, "");
861 json j = vec;