This commit is contained in:
nlohmann committed 2026-10-29 06:46:38 +00:00
1 parent 40c9f42917
commit cf84df303b
14 files changed
+463 -412

No files matched your search

+11
View File
@@ -18,6 +18,16 @@ Whether parsing should proceed.
It is safe to move the passed object key value.
When parsing JSON text, `val` is the decoded object name, not its spelling in the input:
- All escape sequences (`\"`, `\\`, `\/`, `\b`, `\f`, `\n`, `\r`, `\t`, `\uXXXX`, and surrogate pairs) are decoded, and `\uXXXX` escapes are stored as UTF-8. Different spellings of the same name, such as `"/"` and `"\/"`, or `"\u00e9"` and `"\u00E9"`, yield identical strings. An escaped `\u0000` yields an embedded NUL byte.
- The name is scanned and validated completely before `key` is called. If it contains an invalid escape sequence, an unpaired surrogate, a control character, or ill-formed UTF-8, the parse fails with a [`parse_error`](https://json.nlohmann.me/home/exceptions/#parse-errors), and `key` is not called for it.
- No Unicode normalization or case conversion is applied: names that differ in any byte are different strings.
- `key` is called before the following `:` is read, so a parse error may still follow for the same member.
- A name that occurs several times in the same object is passed once per occurrence.
For the binary formats, object keys contain no escape sequences. For CBOR, MessagePack, UBJSON, and BSON, `val` holds the bytes stored in the input, and [`sax_parse`](https://json.nlohmann.me/api/basic_json/sax_parse/index.md) passes them unchanged, without checking them for valid UTF-8. BON8 encodes characters itself, so an ill-formed name is a parse error and `key` is not called for it.
## Examples
Example
@@ -210,3 +220,4 @@ result: false
## Version history
- Added in version 3.2.0.
- The behavior described in the notes above (decoded names, validation before `key` is called, no normalization, `key` before the `:` check, one call per duplicate, bytes of binary formats passed unchanged) is the same in all versions from 3.2.0 on, and for the `key` event of a [parser callback](https://json.nlohmann.me/api/basic_json/parser_callback_t/index.md) from 3.0.0 on. BSON is only supported from version 3.4.0, and BON8 only from version 3.13.0 unreleased.