diff --git a/api/basic_json/to_bjdata.md b/api/basic_json/to_bjdata.md index df3b69004..583139068 100644 --- a/api/basic_json/to_bjdata.md +++ b/api/basic_json/to_bjdata.md @@ -68,6 +68,8 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va - Throws [type_error.316](../../home/exceptions.md#jsonexceptiontype_error316) if a string or object key in `j` is not valid UTF-8 and `error_handler` is `strict` (the default only if [`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled) +- Throws [type_error.321](../../home/exceptions.md#jsonexceptiontype_error321) if `j` or a value nested in it is + discarded; example: `"cannot serialize discarded value to BJData"` ## Complexity @@ -119,4 +121,6 @@ Linear in the size of the JSON value `j`. - BJData version parameter (for draft3 binary encoding) added in version 3.12.0. - Added `error_handler` parameter in version 3.13.0. Its default, `keep`, writes the bytes of a string or object key that is not valid UTF-8 unchanged, as before; `strict` (the default if - [`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled) throws `type_error.316`. \ No newline at end of file + [`JSON_STRICT_BINARY_UTF8`](../macros/json_strict_binary_utf8.md) is enabled) throws `type_error.316`. +- Throws `type_error.321` for a discarded value since version 3.13.0; previously, a discarded value nested in an + array or object was silently skipped, producing invalid BJData. \ No newline at end of file diff --git a/api/basic_json/to_bjdata/index.html b/api/basic_json/to_bjdata/index.html index 2d5971afb..73521049b 100644 --- a/api/basic_json/to_bjdata/index.html +++ b/api/basic_json/to_bjdata/index.html @@ -14,7 +14,7 @@ const bool use_size = false, const bool use_type = false, const bjdata_version_t version = bjdata_version_t::draft2, const error_handler_t error_handler = error_handler_t::keep); -
Serializes a given JSON value j to a byte vector using the BJData (Binary JData) serialization format. BJData aims to be more compact than JSON itself, yet more efficient to parse.
The exact mapping and its limitations are described on a dedicated page.
j (in)o (in)use_size (in)false by default.use_type (in)use_size = true); optional, false by default.version (in)bjdata_version_t::draft2 by default.error_handler (in)j that is not valid UTF-8; see error_handler_t. The default, keep, writes the ill-formed bytes to the output as is, as every version of to_bjdata did before this parameter was added; strict throws; replace/ignore sanitize it the same way dump would. If JSON_STRICT_BINARY_UTF8 is enabled, the default is strict instead.Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
other_error.502 if use_type is true and use_size is false, and j contains a non-empty array, object, or binary value.j is not valid UTF-8 and error_handler is strict (the default only if JSON_STRICT_BINARY_UTF8 is enabled)Linear in the size of the JSON value j.
The example shows the serialization of a JSON value to a byte vector in BJData format.
#include <iostream>
+Serializes a given JSON value j to a byte vector using the BJData (Binary JData) serialization format. BJData aims to be more compact than JSON itself, yet more efficient to parse.
The exact mapping and its limitations are described on a dedicated page.
j (in)o (in)use_size (in)false by default.use_type (in)use_size = true); optional, false by default.version (in)bjdata_version_t::draft2 by default.error_handler (in)j that is not valid UTF-8; see error_handler_t. The default, keep, writes the ill-formed bytes to the output as is, as every version of to_bjdata did before this parameter was added; strict throws; replace/ignore sanitize it the same way dump would. If JSON_STRICT_BINARY_UTF8 is enabled, the default is strict instead.Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
other_error.502 if use_type is true and use_size is false, and j contains a non-empty array, object, or binary value.j is not valid UTF-8 and error_handler is strict (the default only if JSON_STRICT_BINARY_UTF8 is enabled)j or a value nested in it is discarded; example: "cannot serialize discarded value to BJData"Linear in the size of the JSON value j.
The example shows the serialization of a JSON value to a byte vector in BJData format.
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
@@ -103,4 +103,4 @@
}
}
Output:
[json.exception.other_error.502] use_type requires use_size = true
-error_handler parameter in version 3.13.0 unreleased. Its default, keep, writes the bytes of a string or object key that is not valid UTF-8 unchanged, as before; strict (the default if JSON_STRICT_BINARY_UTF8 is enabled) throws type_error.316.