This commit is contained in:
nlohmann
2026-10-04 15:46:44 +00:00
parent 19f538472d
commit c51ca275d0
374 changed files with 1998 additions and 551 deletions
File diff suppressed because one or more lines are too long
+8 -2
View File
@@ -5,12 +5,14 @@
template<typename InputType>
static basic_json from_bson(InputType&& i,
const bool strict = true,
const bool allow_exceptions = true);
const bool allow_exceptions = true,
const error_handler_t error_handler = error_handler_t::keep);
// (2)
template<typename IteratorType, typename SentinelType = IteratorType>
static basic_json from_bson(IteratorType first, SentinelType last,
const bool strict = true,
const bool allow_exceptions = true);
const bool allow_exceptions = true,
const error_handler_t error_handler = error_handler_t::keep);
```
Deserializes a given input to a JSON value using the BSON (Binary JSON) serialization format.
@@ -54,6 +56,8 @@ The exact mapping and its limitations are described on a [dedicated page](https:
`allow_exceptions` (in) : whether to throw exceptions in case of a parse error (optional, `true` by default)
`error_handler` (in) : how to treat a string value or object key that is not valid UTF-8; see [`error_handler_t`](https://json.nlohmann.me/api/basic_json/error_handler_t/index.md). BSON does not require a decoder to reject ill-formed UTF-8, so checking is opt-in: the default, `keep`, does not check at all, as every binary reader did before this parameter was added; `strict` checks and throws; `replace`/`ignore` sanitize the string the same way [`dump`](https://json.nlohmann.me/api/basic_json/dump/index.md) would
## Return value
deserialized JSON value; in case of a parse error and `allow_exceptions` set to `false`, the return value will be `value_t::discarded`. The latter can be checked with [`is_discarded`](https://json.nlohmann.me/api/basic_json/is_discarded/index.md).
@@ -67,6 +71,7 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
- Throws [`parse_error.110`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error110) if the given input ends prematurely or the end of the input was not reached when `strict` was set to true
- Throws [`parse_error.112`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error112) if a parse error occurs (e.g., an invalid string or byte array length)
- Throws [`parse_error.114`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error114) if an unsupported BSON record type is encountered
- Throws [`parse_error.113`](https://json.nlohmann.me/home/exceptions/#jsonexceptionparse_error113) if a string value or object key is not valid UTF-8 and `error_handler` is `strict`
## Complexity
@@ -126,6 +131,7 @@ Output:
- Added in version 3.4.0.
- Extended container support (1) to include types with lvalue-only ADL `begin`/`end` (matching `std::begin`/`std::end` semantics) in version 3.13.0 unreleased.
- Extended overload (2) to accept heterogeneous iterator+sentinel pairs (C++20 ranges support) in version 3.13.0 unreleased.
- Added `error_handler` parameter in version 3.13.0 unreleased.
Deprecation