Lines Matching full:json
3 __| | __| | | | JSON for Modern C++ (test suite)
5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
32 #include <nlohmann/json.hpp>
33 using nlohmann::json;
46 json j = nullptr;
47 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
48 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
55 json j = true;
56 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
57 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
62 json j = false;
63 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
64 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
70 json j = 42;
71 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
72 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
77 json j = 4.2;
78 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
79 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
84 json j = "not supported";
85 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
86 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
91 json j = std::vector<int> {1, 2, 3, 4, 5, 6, 7};
92 CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
93 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-lev…
99 json j =
103 CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
104 …CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.409] BSON key cannot contain cod…
117 json _;
118 CHECK_THROWS_AS(_ = json::from_bson(v), json::parse_error&);
119 …CHECK_THROWS_WITH(_ = json::from_bson(v), "[json.exception.parse_error.112] parse error at byte 10…
126 json j = json::object();
134 const auto result = json::to_bson(j);
138 CHECK(json::from_bson(result) == j);
139 CHECK(json::from_bson(result, true, false) == j);
144 json j =
158 const auto result = json::to_bson(j);
162 CHECK(json::from_bson(result) == j);
163 CHECK(json::from_bson(result, true, false) == j);
168 json j =
182 const auto result = json::to_bson(j);
186 CHECK(json::from_bson(result) == j);
187 CHECK(json::from_bson(result, true, false) == j);
192 json j =
206 const auto result = json::to_bson(j);
210 CHECK(json::from_bson(result) == j);
211 CHECK(json::from_bson(result, true, false) == j);
216 json j =
230 const auto result = json::to_bson(j);
234 CHECK(json::from_bson(result) == j);
235 CHECK(json::from_bson(result, true, false) == j);
240 json j =
253 const auto result = json::to_bson(j);
257 CHECK(json::from_bson(result) == j);
258 CHECK(json::from_bson(result, true, false) == j);
263 json j =
277 const auto result = json::to_bson(j);
281 CHECK(json::from_bson(result) == j);
282 CHECK(json::from_bson(result, true, false) == j);
287 json j =
301 const auto result = json::to_bson(j);
305 CHECK(json::from_bson(result) == j);
306 CHECK(json::from_bson(result, true, false) == j);
311 json j =
325 const auto result = json::to_bson(j);
329 CHECK(json::from_bson(result) == j);
330 CHECK(json::from_bson(result, true, false) == j);
335 json j =
349 const auto result = json::to_bson(j);
353 CHECK(json::from_bson(result) == j);
354 CHECK(json::from_bson(result, true, false) == j);
360 json j =
374 const auto result = json::to_bson(j);
378 CHECK(json::from_bson(result) == j);
379 CHECK(json::from_bson(result, true, false) == j);
384 json j =
398 const auto result = json::to_bson(j);
402 CHECK(json::from_bson(result) == j);
403 CHECK(json::from_bson(result, true, false) == j);
408 json j =
410 { "entry", json::object() }
426 const auto result = json::to_bson(j);
430 CHECK(json::from_bson(result) == j);
431 CHECK(json::from_bson(result, true, false) == j);
436 json j =
438 { "entry", json::array() }
454 const auto result = json::to_bson(j);
458 CHECK(json::from_bson(result) == j);
459 CHECK(json::from_bson(result, true, false) == j);
464 json j =
466 { "entry", json::array({1, 2, 3, 4, 5, 6, 7, 8}) }
489 const auto result = json::to_bson(j);
493 CHECK(json::from_bson(result) == j);
494 CHECK(json::from_bson(result, true, false) == j);
501 json j =
503 { "entry", json::binary(s, 0) }
519 const auto result = json::to_bson(j);
523 CHECK(json::from_bson(result) == j);
524 CHECK(json::from_bson(result, true, false) == j);
531 json j =
533 { "entry", json::binary(md5hash, 5) }
549 const auto result = json::to_bson(j);
553 CHECK(json::from_bson(result) == j);
554 CHECK(json::from_bson(result, true, false) == j);
560 json j =
581 const auto result = json::to_bson(j);
585 CHECK(json::from_bson(result) == j);
586 CHECK(json::from_bson(result, true, false) == j);
595 json parsed = json::from_bson(input);
596 json expected = {{"hello", "world"}};
598 auto dumped = json::to_bson(parsed);
600 CHECK(json::from_bson(dumped) == expected);
606 json parsed = json::from_bson(input);
607 json expected = {{"BSON", {"awesome", 5.05, 1986}}};
609 auto dumped = json::to_bson(parsed);
611 CHECK(json::from_bson(dumped) == expected);
618 json json_representation =
639 json j2;
640 CHECK_NOTHROW(j2 = json::from_bson(bson_representation));
642 // compare parsed JSON values
650 json::to_bson(json_representation, ss);
651 json j3 = json::from_bson(ss.str());
658 json::to_bson(json_representation, s);
659 json j3 = json::from_bson(s);
666 json::to_bson(json_representation, v);
667 json j3 = json::from_bson(v);
691 bool number_integer(json::number_integer_t) in number_integer()
696 bool number_unsigned(json::number_unsigned_t) in number_unsigned()
701 bool number_float(json::number_float_t, const std::string&) in number_float()
741 bool parse_error(std::size_t, const std::string&, const json::exception&) in parse_error()
762 json _;
763 CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
764 CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
765 …"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BSON cstring: …
767 CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
770 CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
781 json _;
782 CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
783 CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
784 …"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BSON cstring: …
785 CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
788 CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
805 json _;
806 CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
807 CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
808 …"[json.exception.parse_error.110] parse error at byte 28: syntax error while parsing BSON element …
809 CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
812 CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
822 json _;
823 CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
824 CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
825 …"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BSON number: u…
826 CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
829 CHECK(!json::sax_parse(incomplete_bson, &scp, json::input_format_t::bson));
836 json j = {{"key", "value"}};
837 auto bson_vec = json::to_bson(j);
839 CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
844 json j =
846 { "entry", json::array() }
848 auto bson_vec = json::to_bson(j);
850 CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
870 CHECK_THROWS_AS(json::from_bson(input), json::parse_error);
871 …CHECK_THROWS_WITH(json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15…
884 json _;
885 CHECK_THROWS_AS(_ = json::from_bson(bson), json::parse_error&);
886 CHECK_THROWS_WITH(_ = json::from_bson(bson),
887 … "[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF");
888 CHECK(json::from_bson(bson, true, false).is_discarded());
891 CHECK(!json::sax_parse(bson, &scp, json::input_format_t::bson));
922 json j =
945 const auto bson = json::to_bson(j);
948 auto j_roundtrip = json::from_bson(bson);
952 CHECK(json::from_bson(bson, true, false) == j);
994 json j =
1013 const auto bson = json::to_bson(j);
1016 auto j_roundtrip = json::from_bson(bson);
1020 CHECK(json::from_bson(bson, true, false) == j);
1047 json j =
1070 const auto bson = json::to_bson(j);
1073 auto j_roundtrip = json::from_bson(bson);
1077 CHECK(json::from_bson(bson, true, false) == j);
1109 json j =
1127 const auto bson = json::to_bson(j);
1130 auto j_roundtrip = json::from_bson(bson);
1135 CHECK(json::from_bson(bson, true, false) == j);
1164 json j =
1186 const auto bson = json::to_bson(j);
1189 auto j_roundtrip = json::from_bson(bson);
1194 CHECK(json::from_bson(bson, true, false) == j);
1214 json j =
1236 CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
1237 …CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + …
1251 TEST_DATA_DIRECTORY "/json.org/1.json", in skip()
1252 TEST_DATA_DIRECTORY "/json.org/2.json", in skip()
1253 TEST_DATA_DIRECTORY "/json.org/3.json", in skip()
1254 TEST_DATA_DIRECTORY "/json.org/4.json", in skip()
1255 TEST_DATA_DIRECTORY "/json.org/5.json" in skip()
1262 // parse JSON file in skip()
1264 json j1 = json::parse(f_json); in skip()
1268 json j2; in skip()
1269 CHECK_NOTHROW(j2 = json::from_bson(packed)); in skip()
1271 // compare parsed JSON values in skip()
1277 // parse JSON file in skip()
1279 json j1 = json::parse(f_json); in skip()
1283 json j2; in skip()
1284 CHECK_NOTHROW(j2 = json::from_bson(f_bson)); in skip()
1286 // compare parsed JSON values in skip()
1292 // parse JSON file in skip()
1294 json j1 = json::parse(f_json); in skip()
1298 json j2; in skip()
1299 CHECK_NOTHROW(j2 = json::from_bson({packed.data(), packed.size()})); in skip()
1301 // compare parsed JSON values in skip()
1307 // parse JSON file in skip()
1309 json j1 = json::parse(f_json); in skip()
1317 json::to_bson(j1, vec); in skip()
1323 // serializations create the same JSON value in skip()
1324 CHECK(json::from_bson(vec) == json::from_bson(packed)); in skip()