This commit is contained in:
nlohmann committed 2026-11-12 11:46:38 +00:00
1 parent 8ddeea7128
commit 5097c20962
516 files changed
+7306 -5984

No files matched your search

+4
View File
@@ -102,6 +102,10 @@ Booleans as numbers
A JSON boolean converts to `0` or `1` for every arithmetic type **except** [`number_integer_t`](https://json.nlohmann.me/api/basic_json/number_integer_t/index.md), [`number_unsigned_t`](https://json.nlohmann.me/api/basic_json/number_unsigned_t/index.md) and [`number_float_t`](https://json.nlohmann.me/api/basic_json/number_float_t/index.md) (by default `std::int64_t`, `std::uint64_t`, and `double`), for which `get<T>()` throws [`type_error.302`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error302) ("type must be number, but is boolean"). So `json(true).get<int>()` is `1`, while `json(true).get<std::int64_t>()` and `json(true).get<double>()` throw. This is the behavior of all 3.x versions; [`basic_json_view::get<T>()`](https://json.nlohmann.me/api/basic_json_view/get/index.md) behaves the same.
`std::u8string` conversions
Since version 3.13.0 unreleased, `get<std::u8string>()` (C++20) reads a JSON string; it also accepts an array of numbers, the form in which version 3.12.0 stored a `std::u8string`. Any other JSON type throws [`type_error.302`](https://json.nlohmann.me/home/exceptions/#jsonexceptiontype_error302) ("type must be string or array").
`std::optional` conversions
Prior to version 3.13.0 unreleased, `get<std::optional<T>>()` (and other conversions to `std::optional<T>`) failed to compile in every configuration, due to an internal implementation bug that made the `from_json` overload for `std::optional` unreachable regardless of the [`JSON_USE_IMPLICIT_CONVERSIONS`](https://json.nlohmann.me/api/macros/json_use_implicit_conversions/index.md) setting. This has been fixed.