mirror of
https://github.com/nlohmann/json.git
synced 2026-09-29 11:10:30 +00:00
Clarify that the token 0 is a valid array index in operator[] docs
The note described valid array indices as "a nonempty sequence of digits without a leading 0", which read literally excludes the token "0" itself, contradicting both the code and the /foo/0/0/0 example in the next sentence. Spell out the RFC 6901 grammar instead. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -128,8 +128,8 @@ Strong exception safety: if an exception occurs, the original value stays intact
|
|||||||
|
|
||||||
When the JSON pointer traverses intermediate levels that don't exist at all yet (not just a missing
|
When the JSON pointer traverses intermediate levels that don't exist at all yet (not just a missing
|
||||||
leaf), each missing level is created as an array or an object depending on whether the corresponding
|
leaf), each missing level is created as an array or an object depending on whether the corresponding
|
||||||
pointer token is a valid array index: a token that is a nonempty sequence of digits without a leading
|
pointer token is a valid array index: the token `0`, a sequence of digits that does not begin with `0`,
|
||||||
`0` (or the token `-`) creates an array, and every other token creates an object. For example, on an
|
or the token `-` creates an array, and every other token creates an object. For example, on an
|
||||||
initially `#!json null` value, `/foo/0/0/0` creates nested arrays, while `/foo/one/one/one` creates
|
initially `#!json null` value, `/foo/0/0/0` creates nested arrays, while `/foo/one/one/one` creates
|
||||||
nested objects. Tokens such as `01` or the empty token cannot be array indices (cf. RFC 6901, Sect. 4)
|
nested objects. Tokens such as `01` or the empty token cannot be array indices (cf. RFC 6901, Sect. 4)
|
||||||
and therefore create objects, just as they would if the level already existed as an object. This is not
|
and therefore create objects, just as they would if the level already existed as an object. This is not
|
||||||
|
|||||||
Reference in New Issue
Block a user