Lines Matching full:json
2 // __| | __| | | | JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
18 // for some reason including this after the json header leads to linker errors with VS 2017...
22 #include <nlohmann/json.hpp>
23 using json = nlohmann::json;
95 void from_json(const json& j, Data& data);
96 void from_json(const json& j, Data& data)
118 static NonDefaultFromJsonStruct from_json(json const& /*unused*/) noexcept
152 static NonDefaultConstructible from_json(json const& j)
163 class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
166 explicit sax_no_exception(json& j)
167 : nlohmann::detail::json_sax_dom_parser<json>(j, false)
170 static bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex)
213 inline void from_json(const nlohmann::json& j, FooBar& fb)
227 virtual void _from_json(const json& j)
241 inline void from_json(const json& j, for_3171_base& tb)
256 inline void from_json(const json& j, for_3312& obj)
283 explicit for_3204_bar(std::function<void(json)> /*unused*/) noexcept // NOLINT(performance-unnecessary-value-param)
308 inline for_3333::for_3333(const json& j)
351 json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed) noexcept
354 if (event == json::parse_event_t::value && !parsed.is_primitive())
361 case json::parse_event_t::key:
365 case json::parse_event_t::value:
369 case json::parse_event_t::object_start:
373 case json::parse_event_t::object_end:
377 case json::parse_event_t::array_start:
381 case json::parse_event_t::array_end:
393 auto j = json::parse(geojsonExample, cb, true);
394 CHECK(j == json());
408 SECTION("issue #1045 - Using STL algorithms with JSON containers with expected results?")
410 json diffs = nlohmann::json::array();
411 json m1{{"key1", 42}};
412 json m2{{"key2", 42}};
436 static_assert(!std::is_constructible<json, std::variant<int, float>>::value, "unexpected value");
443 json j =
466 json dump_test;
476 auto s = dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
483 json dump_test;
493 auto s = dump_test.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
498 nlohmann::json dump_test;
509 dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
515 json j = json::parse("[-9223372036854775808]");
522 json j = smallest;
528 json j = {{"root", {{"settings", {{"logging", true}}}}}};
531 auto jptr2 = json::json_pointer{"/root/settings/logging"};
542 json j;
549 auto val = nlohmann::json("one").get<for_1647>();
551 json j = val;
554 SECTION("issue #1715 - json::from_cbor does not respect allow_exceptions = false when input is string literal")
558 json cbor = json::from_cbor("B", true, false);
565 json cbor = json::from_cbor(input, true, false);
571 json cbor = json::from_cbor(std::string("B"), true, false);
576 SECTION("issue #1805 - A pair<T1, T2> is json constructible only if T1 and T2 are json constructible")
578 static_assert(!std::is_constructible<json, std::pair<std::string, NotSerializableData>>::value, "unexpected result");
579 static_assert(!std::is_constructible<json, std::pair<NotSerializableData, std::string>>::value, "unexpected result");
580 static_assert(std::is_constructible<json, std::pair<int, std::string>>::value, "unexpected result");
582 SECTION("issue #1825 - A tuple<Args..> is json constructible only if all T in Args are json constructible")
584 static_assert(!std::is_constructible<json, std::tuple<std::string, NotSerializableData>>::value, "unexpected result");
585 static_assert(!std::is_constructible<json, std::tuple<NotSerializableData, std::string>>::value, "unexpected result");
586 static_assert(std::is_constructible<json, std::tuple<int, std::string>>::value, "unexpected result");
589 SECTION("issue #1983 - JSON patch diff for op=add formation is not as per standard (RFC 6902)")
593 const auto result = json::diff(source, target);
597 SECTION("issue #2067 - cannot serialize binary data to text JSON")
600 json j = json::from_msgpack(data.data(), data.size());
605 json::error_handler_t::strict // Error
611 // see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060
612 json j{{"x", "test"}};
633 json result = json::from_cbor(data, true, false);
637 SECTION("issue #2315 - json.update and vector<pair>does not work with ordered_json")
662 json j = json::parse(ss, nullptr, true, true);
671 json j = json::parse(s);
681 json j = {7, 4};
688 json j = 7;
689 CHECK_THROWS_AS((j.get<std::array<NonDefaultConstructible, 1>>()), json::type_error);
696 json j = {3, 8};
703 json j = {4, 1};
710 json j = {6, 7};
717 json j = 7;
718 CHECK_THROWS_AS((j.get<std::pair<NonDefaultConstructible, int>>()), json::type_error);
725 json j = {9};
731 json j = {9, 8, 7};
739 json j = 7;
740 CHECK_THROWS_AS((j.get<std::tuple<NonDefaultConstructible>>()), json::type_error);
749 nlohmann::json o;
754 nlohmann::json p = o;
756 // call to_json with a non-null JSON value
761 nlohmann::json o;
766 // call to_json with a non-null JSON value
771 SECTION("issue #2824 - encoding of json::exception::what()")
773 json j;
776 CHECK(!json::sax_parse("xyz", &sax));
777 CHECK(*sax_no_exception::error_string == "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'");
786 SECTION("issue #2958 - Inserting in unordered json using a pointer retains the leading slash")
790 json test1;
791 test1[json::json_pointer(p)] = json::object();
795 test2[ordered_json::json_pointer(p)] = json::object();
798 // json::json_pointer and ordered_json::json_pointer are the same type; behave as above
800 test3[json::json_pointer(p)] = json::object();
801 CHECK(std::is_same<json::json_pointer::string_t, ordered_json::json_pointer::string_t>::value);
808 json j = {1, 2, 3, 4};
809 json::to_cbor(j, my_vector);
810 json k = json::from_cbor(my_vector);
819 json j(text_path);
826 CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
833 json j;
856 SECTION("issue #3343 - json and ordered_json are not interchangable")
858 json::object_t jobj({ { "product", "one" } });
870 json j{{ "str", "value"}};
894 SECTION("issue #3428 - Error occurred when converting nlohmann::json to std::any")
896 json j;
908 for_3204_bar bar_from_json([](json) noexcept {}); // NOLINT(performance-unnecessary-value-param)
916 const json j