2.7. Normalized Paths
2.7. Normalized Paths
A Normalized Path is a unique representation of the location of a node in a value that uniquely identifies the node in the value. Specifically, a Normalized Path is a JSONPath query with restricted syntax (defined below), e.g., $['book'][3], which when applied to the value, results in a nodelist consisting of just the node identified by the Normalized Path. Note: A Normalized Path represents the identity of a node in a specific value. There is precisely one Normalized Path identifying any particular node in a value.
A nodelist may be represented compactly in JSON as an array of strings, where the strings are Normalized Paths.
Normalized Paths provide a predictable format that simplifies testing and post-processing of nodelists, e.g., to remove duplicate nodes. Normalized Paths are used in this document as result paths in examples.
Normalized Paths use the canonical bracket notation, rather than dot notation.
Single quotes are used in Normalized Paths to delimit string member names. This reduces the number of characters that need escaping when Normalized Paths appear in strings delimited by double quotes, e.g., in JSON texts.
Certain characters are escaped in Normalized Paths in one and only one way; all other characters are unescaped.
Note: Normalized Paths are singular queries, but not all
singular queries are Normalized Paths. For example, $[-3] is a
singular query but is not a Normalized Path. The Normalized
Path equivalent to $[-3] would have an index equal to the array
length minus 3. (The array length must be at least 3 if $[-3]
is to identify a node.)
normalized-path = root-identifier *(normal-index-segment)
normal-index-segment = "[" normal-selector "]"
normal-selector = normal-name-selector / normal-index-selector
normal-name-selector = %x27 *normal-single-quoted %x27 ; 'string'
normal-single-quoted = normal-unescaped /
ESC normal-escapable
normal-unescaped = ; omit %x0-1F control codes
%x20-26 /
; omit 0x27 '
%x28-5B /
; omit 0x5C \
%x5D-D7FF /
; skip surrogate code points
%xE000-10FFFF
normal-escapable = %x62 / ; b BS backspace U+0008
%x66 / ; f FF form feed U+000C
%x6E / ; n LF line feed U+000A
%x72 / ; r CR carriage return U+000D
%x74 / ; t HT horizontal tab U+0009
"'" / ; ' apostrophe U+0027
"\" / ; \ backslash (reverse solidus) U+005C
(%x75 normal-hexchar)
; certain values u00xx U+00XX
normal-hexchar = "0" "0"
(
("0" %x30-37) / ; "00"-"07"
; omit U+0008-U+000A BS HT LF
("0" %x62) / ; "0b"
; omit U+000C-U+000D FF CR
("0" %x65-66) / ; "0e"-"0f"
("1" normal-HEXDIG)
)
normal-HEXDIG = DIGIT / %x61-66 ; "0"-"9", "a"-"f"
normal-index-selector = "0" / (DIGIT1 *DIGIT)
; non-negative decimal integer
Since there can only be one Normalized Path identifying a given node, the syntax stipulates which characters are escaped and which are not. So the definition of normal-hexchar is designed for hex escaping of characters that are not straightforwardly printable, for example, U+000B LINE TABULATION, but for which no standard JSON escape, such as \n, is available.
2.7.1. Examples
| Path | Normalized Path | Comment |
|---|---|---|
| $.a | $['a'] | Object value |
| $[1] | $[1] | Array index |
| $[-3] | $[2] | Negative array index for |
| an array of length 5 | ||
| $.a.b[1:2] | $['a']['b'][1] | Nested structure |
| $["\u000B"] | $['\u000b'] | Unicode escape |
| $["\u0061"] | $['a'] | Unicode character |
Table 18: Normalized Path Examples