Lines Matching full:json

2 //  __|  |   __|     |   | |  JSON for Modern C++ (supporting code)
4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json
11 #include <nlohmann/json.hpp>
12 using nlohmann::json;
40 bool number_integer(json::number_integer_t /*unused*/)
45 bool number_unsigned(json::number_unsigned_t /*unused*/)
50 bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
90 bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
107 json j = json::value_t::discarded;
108 const auto result = json::to_cbor(j);
115 json j = std::numeric_limits<json::number_float_t>::quiet_NaN();
117 const auto result = json::to_cbor(j);
124 json j = std::numeric_limits<json::number_float_t>::infinity();
126 const auto result = json::to_cbor(j);
132 json j = nullptr;
134 const auto result = json::to_cbor(j);
138 CHECK(json::from_cbor(result) == j);
139 CHECK(json::from_cbor(result, true, false) == j);
146 json j = true;
148 const auto result = json::to_cbor(j);
152 CHECK(json::from_cbor(result) == j);
153 CHECK(json::from_cbor(result, true, false) == j);
158 json j = false;
160 const auto result = json::to_cbor(j);
164 CHECK(json::from_cbor(result) == j);
165 CHECK(json::from_cbor(result, true, false) == j);
191 // create JSON value with integer number
192 json j = i;
211 const auto result = json::to_cbor(j);
229 CHECK(json::from_cbor(result) == j);
230 CHECK(json::from_cbor(result, true, false) == j);
248 // create JSON value with integer number
249 json j = i;
264 const auto result = json::to_cbor(j);
278 CHECK(json::from_cbor(result) == j);
279 CHECK(json::from_cbor(result, true, false) == j);
289 // create JSON value with integer number
290 json j = i;
303 const auto result = json::to_cbor(j);
314 CHECK(json::from_cbor(result) == j);
315 CHECK(json::from_cbor(result, true, false) == j);
321 json j = -9263;
324 const auto result = json::to_cbor(j);
331 CHECK(json::from_cbor(result) == j);
332 CHECK(json::from_cbor(result, true, false) == j);
341 // create JSON value with integer number
342 json j = i;
353 const auto result = json::to_cbor(j);
362 CHECK(json::from_cbor(result) == j);
363 CHECK(json::from_cbor(result, true, false) == j);
373 // create JSON value with integer number
374 json j = i;
384 const auto result = json::to_cbor(j);
392 CHECK(json::from_cbor(result) == j);
393 CHECK(json::from_cbor(result, true, false) == j);
403 // create JSON value with integer number
404 json j = -1;
405 j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
415 const auto result = json::to_cbor(j);
423 CHECK(json::from_cbor(result) == j);
424 CHECK(json::from_cbor(result, true, false) == j);
434 // create JSON value with integer number
435 json j = -1;
436 j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
447 const auto result = json::to_cbor(j);
456 CHECK(json::from_cbor(result) == j);
457 CHECK(json::from_cbor(result, true, false) == j);
467 // create JSON value with integer number
468 json j = -1;
469 j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
481 const auto result = json::to_cbor(j);
491 CHECK(json::from_cbor(result) == j);
492 CHECK(json::from_cbor(result, true, false) == j);
505 // create JSON value with integer number
506 json j = -1;
507 j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
521 const auto result = json::to_cbor(j);
534 CHECK(json::from_cbor(result) == j);
535 CHECK(json::from_cbor(result, true, false) == j);
548 // create JSON value with integer number
549 json j = -1;
550 j.get_ref<json::number_integer_t&>() = static_cast<json::number_integer_t>(i);
568 const auto result = json::to_cbor(j);
585 CHECK(json::from_cbor(result) == j);
586 CHECK(json::from_cbor(result, true, false) == j);
596 // create JSON value with integer number
597 json j = i;
609 const auto result = json::to_msgpack(j);
619 CHECK(json::from_msgpack(result) == j);
632 // create JSON value with unsigned integer number
633 json j = i;
643 const auto result = json::to_cbor(j);
651 CHECK(json::from_cbor(result) == j);
652 CHECK(json::from_cbor(result, true, false) == j);
662 // create JSON value with unsigned integer number
663 json j = i;
674 const auto result = json::to_cbor(j);
684 CHECK(json::from_cbor(result) == j);
685 CHECK(json::from_cbor(result, true, false) == j);
695 // create JSON value with unsigned integer number
696 json j = i;
708 const auto result = json::to_cbor(j);
718 CHECK(json::from_cbor(result) == j);
719 CHECK(json::from_cbor(result, true, false) == j);
732 // create JSON value with unsigned integer number
733 json j = i;
747 const auto result = json::to_cbor(j);
760 CHECK(json::from_cbor(result) == j);
761 CHECK(json::from_cbor(result, true, false) == j);
774 // create JSON value with integer number
775 json j = i;
793 const auto result = json::to_cbor(j);
810 CHECK(json::from_cbor(result) == j);
811 CHECK(json::from_cbor(result, true, false) == j);
821 json j = v;
826 const auto result = json::to_cbor(j);
830 CHECK(json::from_cbor(result) == j);
831 CHECK(json::from_cbor(result) == v);
833 CHECK(json::from_cbor(result, true, false) == j);
842 json j = v;
847 const auto result = json::to_cbor(j);
850 CHECK(json::from_cbor(result) == j);
851 CHECK(json::from_cbor(result) == v);
856 json j = v;
860 const auto result = json::to_cbor(j);
863 CHECK(json::from_cbor(result) == j);
864 CHECK(json::from_cbor(result) == v);
869 json j = v;
873 const auto result = json::to_cbor(j);
876 CHECK(json::from_cbor(result) == j);
877 CHECK(json::from_cbor(result) == v);
882 json j = v;
886 const auto result = json::to_cbor(j);
889 CHECK(json::from_cbor(result) == j);
890 CHECK(json::from_cbor(result) == v);
895 json j = v;
899 const auto result = json::to_cbor(j);
902 CHECK(json::from_cbor(result) == j);
903 CHECK(json::from_cbor(result) == v);
908 json j = v;
913 const auto result = json::to_cbor(j);
916 CHECK(json::from_cbor(result) == j);
917 CHECK(json::from_cbor(result) == v);
922 json j = v;
927 const auto result = json::to_cbor(j);
930 CHECK(json::from_cbor(result) == j);
931 CHECK(json::from_cbor(result) == v);
936 json j = v;
942 const auto result = json::to_cbor(j);
945 CHECK(json::from_cbor(result) == j);
946 CHECK(json::from_cbor(result) == v);
951 json j = v;
957 const auto result = json::to_cbor(j);
960 CHECK(json::from_cbor(result) == j);
961 CHECK(json::from_cbor(result) == v);
972 json _;
973 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xf9})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
974 CHECK(json::from_cbor(std::vector<uint8_t>({0xf9}), true, false).is_discarded());
978 json _;
979 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
980 CHECK(json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c}), true, false).is_discarded());
988 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x00}));
989 json::number_float_t d{j};
995 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x80, 0x00}));
996 json::number_float_t d{j};
1002 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x01}));
1003 json::number_float_t d{j};
1012 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
1013 json::number_float_t d{j};
1014 CHECK(d == std::numeric_limits<json::number_float_t>::infinity());
1020 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0xfc, 0x00}));
1021 json::number_float_t d{j};
1022 CHECK(d == -std::numeric_limits<json::number_float_t>::infinity());
1031 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x3c, 0x00}));
1032 json::number_float_t d{j};
1038 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0xc0, 0x00}));
1039 json::number_float_t d{j};
1045 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7b, 0xff}));
1046 json::number_float_t d{j};
1053 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
1054 json::number_float_t d{j};
1061 json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7e, 0x00}));
1062 json::number_float_t d{j};
1077 // create JSON value with string containing of N * 'x'
1079 json j = s;
1090 const auto result = json::to_cbor(j);
1100 CHECK(json::from_cbor(result) == j);
1101 CHECK(json::from_cbor(result, true, false) == j);
1111 // create JSON value with string containing of N * 'x'
1113 json j = s;
1125 const auto result = json::to_cbor(j);
1132 CHECK(json::from_cbor(result) == j);
1133 CHECK(json::from_cbor(result, true, false) == j);
1146 // create JSON value with string containing of N * 'x'
1148 json j = s;
1158 const auto result = json::to_cbor(j);
1165 CHECK(json::from_cbor(result) == j);
1166 CHECK(json::from_cbor(result, true, false) == j);
1179 // create JSON value with string containing of N * 'x'
1181 json j = s;
1193 const auto result = json::to_cbor(j);
1200 CHECK(json::from_cbor(result) == j);
1201 CHECK(json::from_cbor(result, true, false) == j);
1210 json j = json::array();
1212 const auto result = json::to_cbor(j);
1216 CHECK(json::from_cbor(result) == j);
1217 CHECK(json::from_cbor(result, true, false) == j);
1222 json j = {nullptr};
1224 const auto result = json::to_cbor(j);
1228 CHECK(json::from_cbor(result) == j);
1229 CHECK(json::from_cbor(result, true, false) == j);
1234 json j = json::parse("[1,2,3,4,5]");
1236 const auto result = json::to_cbor(j);
1240 CHECK(json::from_cbor(result) == j);
1241 CHECK(json::from_cbor(result, true, false) == j);
1246 json j = json::parse("[[[[]]]]");
1248 const auto result = json::to_cbor(j);
1252 CHECK(json::from_cbor(result) == j);
1253 CHECK(json::from_cbor(result, true, false) == j);
1258 json j(257, nullptr);
1263 const auto result = json::to_cbor(j);
1267 CHECK(json::from_cbor(result) == j);
1268 CHECK(json::from_cbor(result, true, false) == j);
1273 json j(65793, nullptr);
1280 const auto result = json::to_cbor(j);
1284 CHECK(json::from_cbor(result) == j);
1285 CHECK(json::from_cbor(result, true, false) == j);
1293 json j = json::object();
1295 const auto result = json::to_cbor(j);
1299 CHECK(json::from_cbor(result) == j);
1300 CHECK(json::from_cbor(result, true, false) == j);
1305 json j = {{"", nullptr}};
1307 const auto result = json::to_cbor(j);
1311 CHECK(json::from_cbor(result) == j);
1312 CHECK(json::from_cbor(result, true, false) == j);
1317 json j = json::parse(R"({"a": {"b": {"c": {}}}})");
1322 const auto result = json::to_cbor(j);
1326 CHECK(json::from_cbor(result) == j);
1327 CHECK(json::from_cbor(result, true, false) == j);
1332 json j;
1342 const auto result = json::to_cbor(j);
1353 CHECK(json::from_cbor(result) == j);
1354 CHECK(json::from_cbor(result, true, false) == j);
1359 json j;
1369 const auto result = json::to_cbor(j);
1382 CHECK(json::from_cbor(result) == j);
1383 CHECK(json::from_cbor(result, true, false) == j);
1388 json j;
1398 const auto result = json::to_cbor(j);
1413 CHECK(json::from_cbor(result) == j);
1414 CHECK(json::from_cbor(result, true, false) == j);
1426 // create JSON value with byte array containing of N * 'x'
1428 json j = json::binary(s);
1439 const auto result = json::to_cbor(j);
1449 CHECK(json::from_cbor(result) == j);
1450 CHECK(json::from_cbor(result, true, false) == j);
1460 // create JSON value with string containing of N * 'x'
1462 json j = json::binary(s);
1474 const auto result = json::to_cbor(j);
1481 CHECK(json::from_cbor(result) == j);
1482 CHECK(json::from_cbor(result, true, false) == j);
1495 // create JSON value with string containing of N * 'x'
1497 json j = json::binary(s);
1507 const auto result = json::to_cbor(j);
1514 CHECK(json::from_cbor(result) == j);
1515 CHECK(json::from_cbor(result, true, false) == j);
1528 // create JSON value with string containing of N * 'x'
1530 json j = json::binary(s);
1542 const auto result = json::to_cbor(j);
1549 CHECK(json::from_cbor(result) == j);
1550 CHECK(json::from_cbor(result, true, false) == j);
1557 auto j = json::from_cbor(input);
1559 auto k = json::binary({0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99});
1560 CAPTURE(j.dump(0, ' ', false, json::error_handler_t::strict))
1568 json _;
1569 CHECK_NOTHROW(_ = json::from_cbor(input));
1576 json _;
1577 CHECK_NOTHROW(_ = json::from_cbor(input));
1587 auto callback = [&binary_seen](int /*depth*/, json::parse_event_t /*event*/, json & parsed) noexcept
1596 json j;
1597 auto cbp = nlohmann::detail::json_sax_dom_callback_parser<json>(j, callback, true);
1598 CHECK(json::sax_parse(input, &cbp, json::input_format_t::cbor));
1612 json j = json::from_cbor(given);
1613 CHECK(j == json::binary(std::vector<uint8_t> {'a'}));
1621 json j = json::from_cbor(given);
1630 json j = json::from_cbor(given);
1631 CHECK(j == json::parse("[false]"));
1639 json j = json::from_cbor(given);
1640 CHECK(j == json::parse("{\"\": false}"));
1648 json _;
1649 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
1650 CHECK(json::from_cbor(std::vector<uint8_t>(), true, false).is_discarded());
1655 json _;
1656 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x18})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1657 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x19})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1658 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x19, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1659 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1660 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1661 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1662 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1663 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1664 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1665 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1666 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1667 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1668 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1669 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1670 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
1671 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x62})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
1672 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x62, 0x60})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
1673 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x7F})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
1674 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x7F, 0x60})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
1675 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x82, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
1676 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x9F, 0x01})), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
1677 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61, 0xF5})), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
1678 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xA1, 0x61, 0X61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
1679 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0X61})), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
1680 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x5F})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&);
1681 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x5F, 0x00})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR binary: expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x00", json::parse_error&);
1682 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x41})), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR binary: unexpected end of input", json::parse_error&);
1684 CHECK(json::from_cbor(std::vector<uint8_t>({0x18}), true, false).is_discarded());
1685 CHECK(json::from_cbor(std::vector<uint8_t>({0x19}), true, false).is_discarded());
1686 CHECK(json::from_cbor(std::vector<uint8_t>({0x19, 0x00}), true, false).is_discarded());
1687 CHECK(json::from_cbor(std::vector<uint8_t>({0x1a}), true, false).is_discarded());
1688 CHECK(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00}), true, false).is_discarded());
1689 CHECK(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00}), true, false).is_discarded());
1690 CHECK(json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x00, 0x00}), true, false).is_discarded());
1691 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b}), true, false).is_discarded());
1692 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00}), true, false).is_discarded());
1693 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00}), true, false).is_discarded());
1694 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00}), true, false).is_discarded());
1695 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1696 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1697 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1698 CHECK(json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
1699 CHECK(json::from_cbor(std::vector<uint8_t>({0x62}), true, false).is_discarded());
1700 CHECK(json::from_cbor(std::vector<uint8_t>({0x62, 0x60}), true, false).is_discarded());
1701 CHECK(json::from_cbor(std::vector<uint8_t>({0x7F}), true, false).is_discarded());
1702 CHECK(json::from_cbor(std::vector<uint8_t>({0x7F, 0x60}), true, false).is_discarded());
1703 CHECK(json::from_cbor(std::vector<uint8_t>({0x82, 0x01}), true, false).is_discarded());
1704 CHECK(json::from_cbor(std::vector<uint8_t>({0x9F, 0x01}), true, false).is_discarded());
1705 CHECK(json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61, 0xF5}), true, false).is_discarded());
1706 CHECK(json::from_cbor(std::vector<uint8_t>({0xA1, 0x61, 0x61}), true, false).is_discarded());
1707 CHECK(json::from_cbor(std::vector<uint8_t>({0xBF, 0x61, 0x61}), true, false).is_discarded());
1708 CHECK(json::from_cbor(std::vector<uint8_t>({0x5F}), true, false).is_discarded());
1709 CHECK(json::from_cbor(std::vector<uint8_t>({0x5F, 0x00}), true, false).is_discarded());
1710 CHECK(json::from_cbor(std::vector<uint8_t>({0x41}), true, false).is_discarded());
1717 json _;
1718 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0x1c})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0x1C", json::parse_error&);
1719 CHECK(json::from_cbor(std::vector<uint8_t>({0x1c}), true, false).is_discarded());
1721 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xf8})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing CBOR value: invalid byte: 0xF8", json::parse_error&);
1722 CHECK(json::from_cbor(std::vector<uint8_t>({0xf8}), true, false).is_discarded());
1765 json _;
1766 CHECK_THROWS_AS(_ = json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
1767 CHECK(json::from_cbor(std::vector<uint8_t>({static_cast<uint8_t>(byte)}), true, false).is_discarded());
1774 json _;
1775 CHECK_THROWS_WITH_AS(_ = json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xFF", json::parse_error&);
1776 CHECK(json::from_cbor(std::vector<uint8_t>({0xa1, 0xff, 0x01}), true, false).is_discarded());
1784 const auto result = json::from_cbor(vec, false);
1785 CHECK(result == json());
1786 CHECK(!json::from_cbor(vec, false, false).is_discarded());
1791 json _;
1792 CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: expected end of input; last byte: 0xF6", json::parse_error&);
1793 CHECK(json::from_cbor(vec, true, false).is_discarded());
1804 CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
1811 CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
1818 CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
1826 SECTION("sample.json")
1828 std::string filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json";
1830 // parse JSON file
1832 json j1 = json::parse(f_json);
1836 json j2;
1837 CHECK_NOTHROW(j2 = json::from_cbor(packed));
1839 // compare parsed JSON values
1847 json::to_cbor(j1, ss);
1848 json j3 = json::from_cbor(ss.str());
1855 json::to_cbor(j1, s);
1856 json j3 = json::from_cbor(s);
1863 CHECK(j1 == json::from_cbor(packed.begin() + 5, packed.end()));
1908 json j1 = json::from_cbor(vec1);
1913 std::vector<uint8_t> vec2 = json::to_cbor(j1);
1916 json j2 = json::from_cbor(vec2);
1921 catch (const json::parse_error&)
1927 catch (const json::parse_error&)
1942 exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json");
1943 exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json");
1944 exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json");
1945 exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json");
1946 exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json");
1947 exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor
1948 exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json");
1949 exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json");
1950 exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json");
1951 exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
1952 exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");
1956 TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
1957 TEST_DATA_DIRECTORY "/json.org/1.json",
1958 TEST_DATA_DIRECTORY "/json.org/2.json",
1959 TEST_DATA_DIRECTORY "/json.org/3.json",
1960 TEST_DATA_DIRECTORY "/json.org/4.json",
1961 TEST_DATA_DIRECTORY "/json.org/5.json",
1962 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
1963 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
1964 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
1965 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
1966 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
1967 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
1968 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
1969 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
1970 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
1971 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
1972 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
1973 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
1974 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
1975 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
1976 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
1977 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
1978 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
1979 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
1980 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
1981 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
1982 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
1983 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
1984 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
1985 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
1986 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
1987 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
1988 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
1989 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
1990 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
1991 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
1992 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
1993 TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
1994 TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
1995 TEST_DATA_DIRECTORY "/json_tests/pass1.json",
1996 TEST_DATA_DIRECTORY "/json_tests/pass2.json",
1997 TEST_DATA_DIRECTORY "/json_tests/pass3.json",
1998 TEST_DATA_DIRECTORY "/regression/floats.json",
1999 TEST_DATA_DIRECTORY "/regression/signed_ints.json",
2000 TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
2001 TEST_DATA_DIRECTORY "/regression/working_file.json",
2002 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
2003 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
2004 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json",
2005 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
2006 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
2007 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
2008 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
2009 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
2010 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
2011 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
2012 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
2013 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
2014 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
2015 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
2016 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
2017 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
2018 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
2019 //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
2020 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
2021 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
2022 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
2023 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
2024 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
2025 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
2026 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
2027 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
2028 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
2029 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
2030 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
2031 //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
2032 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
2033 //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
2034 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
2035 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
2036 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
2037 //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
2038 //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
2039 //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
2040 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
2041 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
2042 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
2043 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
2044 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
2045 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
2046 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
2047 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
2048 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
2049 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json",
2050 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
2051 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
2052 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
2053 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
2054 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
2055 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
2056 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
2057 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
2058 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
2059 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
2060 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
2061 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
2062 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
2063 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
2064 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
2065 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
2066 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
2067 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
2068 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
2069 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
2070 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
2071 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
2072 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
2073 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
2074 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
2075 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
2076 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
2077 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
2078 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
2079 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
2080 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
2081 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
2082 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
2083 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
2084 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
2085 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
2086 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
2087 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
2088 // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
2089 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
2090 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
2091 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
2092 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
2093 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
2094 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
2095 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
2096 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
2097 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
2098 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
2099 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
2100 TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"
2107 // parse JSON file
2109 json j1 = json::parse(f_json);
2113 json j2;
2114 CHECK_NOTHROW(j2 = json::from_cbor(packed));
2116 // compare parsed JSON values
2122 // parse JSON file
2124 json j1 = json::parse(f_json);
2128 json j2;
2129 CHECK_NOTHROW(j2 = json::from_cbor(f_cbor));
2131 // compare parsed JSON values
2137 // parse JSON file
2139 json j1 = json::parse(f_json);
2143 json j2;
2144 CHECK_NOTHROW(j2 = json::from_cbor({packed.data(), packed.size()}));
2146 // compare parsed JSON values
2152 // parse JSON file
2154 json j1 = json::parse(f_json);
2164 json::to_cbor(j1, vec);
2226 auto res = json::from_cbor(std::vector<uint8_t>(1, byte));
2228 catch (const json::parse_error& e)
2250 CHECK(json::to_cbor(json::parse("0")) == std::vector<uint8_t>({0x00}));
2251 CHECK(json::parse("0") == json::from_cbor(std::vector<uint8_t>({0x00})));
2253 CHECK(json::to_cbor(json::parse("1")) == std::vector<uint8_t>({0x01}));
2254 CHECK(json::parse("1") == json::from_cbor(std::vector<uint8_t>({0x01})));
2256 CHECK(json::to_cbor(json::parse("10")) == std::vector<uint8_t>({0x0a}));
2257 CHECK(json::parse("10") == json::from_cbor(std::vector<uint8_t>({0x0a})));
2259 CHECK(json::to_cbor(json::parse("23")) == std::vector<uint8_t>({0x17}));
2260 CHECK(json::parse("23") == json::from_cbor(std::vector<uint8_t>({0x17})));
2262 CHECK(json::to_cbor(json::parse("24")) == std::vector<uint8_t>({0x18, 0x18}));
2263 CHECK(json::parse("24") == json::from_cbor(std::vector<uint8_t>({0x18, 0x18})));
2265 CHECK(json::to_cbor(json::parse("25")) == std::vector<uint8_t>({0x18, 0x19}));
2266 CHECK(json::parse("25") == json::from_cbor(std::vector<uint8_t>({0x18, 0x19})));
2268 CHECK(json::to_cbor(json::parse("100")) == std::vector<uint8_t>({0x18, 0x64}));
2269 CHECK(json::parse("100") == json::from_cbor(std::vector<uint8_t>({0x18, 0x64})));
2271 CHECK(json::to_cbor(json::parse("1000")) == std::vector<uint8_t>({0x19, 0x03, 0xe8}));
2272 CHECK(json::parse("1000") == json::from_cbor(std::vector<uint8_t>({0x19, 0x03, 0xe8})));
2274 CHECK(json::to_cbor(json::parse("1000000")) == std::vector<uint8_t>({0x1a, 0x00, 0x0f, 0x42, 0x40}));
2275 CHECK(json::parse("1000000") == json::from_cbor(std::vector<uint8_t>({0x1a, 0x00, 0x0f, 0x42, 0x40})));
2277 CHECK(json::to_cbor(json::parse("1000000000000")) == std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0xe8, 0xd4, 0xa5, 0x10, 0x00}));
2278 CHECK(json::parse("1000000000000") == json::from_cbor(std::vector<uint8_t>({0x1b, 0x00, 0x00, 0x00, 0xe8, 0xd4, 0xa5, 0x10, 0x00})));
2280 CHECK(json::to_cbor(json::parse("18446744073709551615")) == std::vector<uint8_t>({0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}));
2281 CHECK(json::parse("18446744073709551615") == json::from_cbor(std::vector<uint8_t>({0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})));
2284 //CHECK(json::to_cbor(json::parse("18446744073709551616")) == std::vector<uint8_t>({0xc2, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
2285 //CHECK(json::parse("18446744073709551616") == json::from_cbor(std::vector<uint8_t>({0xc2, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})));
2287 //CHECK(json::to_cbor(json::parse("-18446744073709551616")) == std::vector<uint8_t>({0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}));
2288 //CHECK(json::parse("-18446744073709551616") == json::from_cbor(std::vector<uint8_t>({0x3b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})));
2291 //CHECK(json::to_cbor(json::parse("-18446744073709551617")) == std::vector<uint8_t>({0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
2292 //CHECK(json::parse("-18446744073709551617") == json::from_cbor(std::vector<uint8_t>({0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})));
2294 CHECK(json::to_cbor(json::parse("-1")) == std::vector<uint8_t>({0x20}));
2295 CHECK(json::parse("-1") == json::from_cbor(std::vector<uint8_t>({0x20})));
2297 CHECK(json::to_cbor(json::parse("-10")) == std::vector<uint8_t>({0x29}));
2298 CHECK(json::parse("-10") == json::from_cbor(std::vector<uint8_t>({0x29})));
2300 CHECK(json::to_cbor(json::parse("-100")) == std::vector<uint8_t>({0x38, 0x63}));
2301 CHECK(json::parse("-100") == json::from_cbor(std::vector<uint8_t>({0x38, 0x63})));
2303 CHECK(json::to_cbor(json::parse("-1000")) == std::vector<uint8_t>({0x39, 0x03, 0xe7}));
2304 CHECK(json::parse("-1000") == json::from_cbor(std::vector<uint8_t>({0x39, 0x03, 0xe7})));
2307 //CHECK(json::to_cbor(json::parse("0.0")) == std::vector<uint8_t>({0xf9, 0x00, 0x00}));
2308 CHECK(json::parse("0.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x00})));
2311 //CHECK(json::to_cbor(json::parse("-0.0")) == std::vector<uint8_t>({0xf9, 0x80, 0x00}));
2312 CHECK(json::parse("-0.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0x80, 0x00})));
2315 //CHECK(json::to_cbor(json::parse("1.0")) == std::vector<uint8_t>({0xf9, 0x3c, 0x00}));
2316 CHECK(json::parse("1.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0x3c, 0x00})));
2318 CHECK(json::to_cbor(json::parse("1.1")) == std::vector<uint8_t>({0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a}));
2319 CHECK(json::parse("1.1") == json::from_cbor(std::vector<uint8_t>({0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a})));
2322 //CHECK(json::to_cbor(json::parse("1.5")) == std::vector<uint8_t>({0xf9, 0x3e, 0x00}));
2323 CHECK(json::parse("1.5") == json::from_cbor(std::vector<uint8_t>({0xf9, 0x3e, 0x00})));
2326 //CHECK(json::to_cbor(json::parse("65504.0")) == std::vector<uint8_t>({0xf9, 0x7b, 0xff}));
2327 CHECK(json::parse("65504.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0x7b, 0xff})));
2329 //CHECK(json::to_cbor(json::parse("100000.0")) == std::vector<uint8_t>({0xfa, 0x47, 0xc3, 0x50, 0x00}));
2330 CHECK(json::parse("100000.0") == json::from_cbor(std::vector<uint8_t>({0xfa, 0x47, 0xc3, 0x50, 0x00})));
2332 //CHECK(json::to_cbor(json::parse("3.4028234663852886e+38")) == std::vector<uint8_t>({0xfa, 0x7f, 0x7f, 0xff, 0xff}));
2333 CHECK(json::parse("3.4028234663852886e+38") == json::from_cbor(std::vector<uint8_t>({0xfa, 0x7f, 0x7f, 0xff, 0xff})));
2335 CHECK(json::to_cbor(json::parse("1.0e+300")) == std::vector<uint8_t>({0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c}));
2336 CHECK(json::parse("1.0e+300") == json::from_cbor(std::vector<uint8_t>({0xfb, 0x7e, 0x37, 0xe4, 0x3c, 0x88, 0x00, 0x75, 0x9c})));
2339 //CHECK(json::to_cbor(json::parse("5.960464477539063e-8")) == std::vector<uint8_t>({0xf9, 0x00, 0x01}));
2340 CHECK(json::parse("-4.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0xc4, 0x00})));
2343 //CHECK(json::to_cbor(json::parse("0.00006103515625")) == std::vector<uint8_t>({0xf9, 0x04, 0x00}));
2344 CHECK(json::parse("-4.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0xc4, 0x00})));
2347 //CHECK(json::to_cbor(json::parse("-4.0")) == std::vector<uint8_t>({0xf9, 0xc4, 0x00}));
2348 CHECK(json::parse("-4.0") == json::from_cbor(std::vector<uint8_t>({0xf9, 0xc4, 0x00})));
2350 CHECK(json::to_cbor(json::parse("-4.1")) == std::vector<uint8_t>({0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66}));
2351 CHECK(json::parse("-4.1") == json::from_cbor(std::vector<uint8_t>({0xfb, 0xc0, 0x10, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66})));
2356 CHECK(json::to_cbor(json::parse("false")) == std::vector<uint8_t>({0xf4}));
2357 CHECK(json::parse("false") == json::from_cbor(std::vector<uint8_t>({0xf4})));
2359 CHECK(json::to_cbor(json::parse("true")) == std::vector<uint8_t>({0xf5}));
2360 CHECK(json::parse("true") == json::from_cbor(std::vector<uint8_t>({0xf5})));
2362 CHECK(json::to_cbor(json::parse("true")) == std::vector<uint8_t>({0xf5}));
2363 CHECK(json::parse("true") == json::from_cbor(std::vector<uint8_t>({0xf5})));
2368 CHECK(json::to_cbor(json::parse("\"\"")) == std::vector<uint8_t>({0x60}));
2369 CHECK(json::parse("\"\"") == json::from_cbor(std::vector<uint8_t>({0x60})));
2371 CHECK(json::to_cbor(json::parse("\"a\"")) == std::vector<uint8_t>({0x61, 0x61}));
2372 CHECK(json::parse("\"a\"") == json::from_cbor(std::vector<uint8_t>({0x61, 0x61})));
2374 CHECK(json::to_cbor(json::parse("\"IETF\"")) == std::vector<uint8_t>({0x64, 0x49, 0x45, 0x54, 0x46}));
2375 CHECK(json::parse("\"IETF\"") == json::from_cbor(std::vector<uint8_t>({0x64, 0x49, 0x45, 0x54, 0x46})));
2377 CHECK(json::to_cbor(json::parse("\"\\u00fc\"")) == std::vector<uint8_t>({0x62, 0xc3, 0xbc}));
2378 CHECK(json::parse("\"\\u00fc\"") == json::from_cbor(std::vector<uint8_t>({0x62, 0xc3, 0xbc})));
2380 CHECK(json::to_cbor(json::parse("\"\\u6c34\"")) == std::vector<uint8_t>({0x63, 0xe6, 0xb0, 0xb4}));
2381 CHECK(json::parse("\"\\u6c34\"") == json::from_cbor(std::vector<uint8_t>({0x63, 0xe6, 0xb0, 0xb4})));
2383 CHECK(json::to_cbor(json::parse("\"\\ud800\\udd51\"")) == std::vector<uint8_t>({0x64, 0xf0, 0x90, 0x85, 0x91}));
2384 CHECK(json::parse("\"\\ud800\\udd51\"") == json::from_cbor(std::vector<uint8_t>({0x64, 0xf0, 0x90, 0x85, 0x91})));
2387 CHECK(json::parse("\"streaming\"") == json::from_cbor(std::vector<uint8_t>({0x7f, 0x65, 0x73, 0x74, 0x72, 0x65, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x67, 0xff})));
2393 json j;
2394 CHECK_NOTHROW(j = json::from_cbor(packed));
2397 CHECK(j == json::binary(expected));
2400 CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 0x42)) == std::vector<uint8_t> {0xd8, 0x42, 0x40});
2401 CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 0x42)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype());
2402 CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 0x42)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 0x42);
2404 CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 1000)) == std::vector<uint8_t> {0xd9, 0x03, 0xe8, 0x40});
2405 CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 1000)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype());
2406 CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 1000)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 1000);
2408 CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 394216)) == std::vector<uint8_t> {0xda, 0x00, 0x06, 0x03, 0xe8, 0x40});
2409 CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 394216)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype());
2410 CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 394216)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 394216);
2412 CHECK(json::to_cbor(json::binary(std::vector<uint8_t> {}, 8589934590)) == std::vector<uint8_t> {0xdb, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xfe, 0x40});
2413 CHECK(!json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 8589934590)), true, true, json::cbor_tag_handler_t::ignore).get_binary().has_subtype());
2414 CHECK(json::from_cbor(json::to_cbor(json::binary(std::vector<uint8_t> {}, 8589934590)), true, true, json::cbor_tag_handler_t::store).get_binary().subtype() == 8589934590);
2419 CHECK(json::to_cbor(json::parse("[]")) == std::vector<uint8_t>({0x80}));
2420 CHECK(json::parse("[]") == json::from_cbor(std::vector<uint8_t>({0x80})));
2422 CHECK(json::to_cbor(json::parse("[1, 2, 3]")) == std::vector<uint8_t>({0x83, 0x01, 0x02, 0x03}));
2423 CHECK(json::parse("[1, 2, 3]") == json::from_cbor(std::vector<uint8_t>({0x83, 0x01, 0x02, 0x03})));
2425 CHECK(json::to_cbor(json::parse("[1, [2, 3], [4, 5]]")) == std::vector<uint8_t>({0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05}));
2426 CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector<uint8_t>({0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05})));
2428 CHECK(json::to_cbor(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]")) == std::vector<uint8_t>({0x98, 0x19, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19}));
2429 CHECK(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]") == json::from_cbor(std::vector<uint8_t>({0x98, 0x19, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19})));
2432 CHECK(json::parse("[]") == json::from_cbor(std::vector<uint8_t>({0x9f, 0xff})));
2433 CHECK(json::parse("[1, [2, 3], [4, 5]] ") == json::from_cbor(std::vector<uint8_t>({0x9f, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff, 0xff})));
2434 CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector<uint8_t>({0x9f, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05, 0xff})));
2435 CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector<uint8_t>({0x83, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff})));
2436 CHECK(json::parse("[1, [2, 3], [4, 5]]") == json::from_cbor(std::vector<uint8_t>({0x83, 0x01, 0x9f, 0x02, 0x03, 0xff, 0x82, 0x04, 0x05})));
2437 CHECK(json::parse("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]") == json::from_cbor(std::vector<uint8_t>({0x9f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19, 0xff})));
2442 CHECK(json::to_cbor(json::parse("{}")) == std::vector<uint8_t>({0xa0}));
2443 CHECK(json::parse("{}") == json::from_cbor(std::vector<uint8_t>({0xa0})));
2445 CHECK(json::to_cbor(json::parse("{\"a\": 1, \"b\": [2, 3]}")) == std::vector<uint8_t>({0xa2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03}));
2446 CHECK(json::parse("{\"a\": 1, \"b\": [2, 3]}") == json::from_cbor(std::vector<uint8_t>({0xa2, 0x61, 0x61, 0x01, 0x61, 0x62, 0x82, 0x02, 0x03})));
2448 CHECK(json::to_cbor(json::parse("[\"a\", {\"b\": \"c\"}]")) == std::vector<uint8_t>({0x82, 0x61, 0x61, 0xa1, 0x61, 0x62, 0x61, 0x63}));
2449 CHECK(json::parse("[\"a\", {\"b\": \"c\"}]") == json::from_cbor(std::vector<uint8_t>({0x82, 0x61, 0x61, 0xa1, 0x61, 0x62, 0x61, 0x63})));
2451 CHECK(json::to_cbor(json::parse("{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E\"}")) == std::vector<uint8_t>({0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61, 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61, 0x44, 0x61, 0x65, 0x61, 0x45}));
2452 CHECK(json::parse("{\"a\": \"A\", \"b\": \"B\", \"c\": \"C\", \"d\": \"D\", \"e\": \"E\"}") == json::from_cbor(std::vector<uint8_t>({0xa5, 0x61, 0x61, 0x61, 0x41, 0x61, 0x62, 0x61, 0x42, 0x61, 0x63, 0x61, 0x43, 0x61, 0x64, 0x61, 0x44, 0x61, 0x65, 0x61, 0x45})));
2455 CHECK(json::parse("{\"a\": 1, \"b\": [2, 3]}") == json::from_cbor(std::vector<uint8_t>({0xbf, 0x61, 0x61, 0x01, 0x61, 0x62, 0x9f, 0x02, 0x03, 0xff, 0xff})));
2456 CHECK(json::parse("[\"a\", {\"b\": \"c\"}]") == json::from_cbor(std::vector<uint8_t>({0x82, 0x61, 0x61, 0xbf, 0x61, 0x62, 0x61, 0x63, 0xff})));
2457 CHECK(json::parse("{\"Fun\": true, \"Amt\": -2}") == json::from_cbor(std::vector<uint8_t>({0xbf, 0x63, 0x46, 0x75, 0x6e, 0xf5, 0x63, 0x41, 0x6d, 0x74, 0x21, 0xff})));
2463 json j = "s";
2464 auto v = json::to_cbor(j);
2480 json _;
2481 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2482 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2485 auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
2488 auto j_tagged_stored = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::store);
2503 json _;
2504 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2505 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2508 auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
2519 json _;
2520 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2521 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2522 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
2537 json _;
2538 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2539 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2542 auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
2554 json _;
2555 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2556 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2557 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
2574 json _;
2575 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2576 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2579 auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
2593 json _;
2594 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2595 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2596 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
2617 json _;
2618 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2619 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2622 auto j_tagged = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore);
2640 json _;
2641 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged), json::parse_error);
2642 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::error), json::parse_error);
2643 CHECK_THROWS_AS(_ = json::from_cbor(v_tagged, true, true, json::cbor_tag_handler_t::ignore), json::parse_error);
2650 json j_binary;
2651 j_binary["binary"] = json::binary({0xCA, 0xFE, 0xBA, 0xBE}, 42);
2654 const auto vec = json::to_cbor(j_binary);
2658 json _;
2659 CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.112] parse error at byte 9: syntax error while parsing CBOR value: invalid byte: 0xD8", json::parse_error);
2662 json jb = json::from_cbor(vec, true, true, json::cbor_tag_handler_t::ignore);