D-44139
+
+ D-28359
+ Syntax Element | +Description | +
---|---|
+ $ | +
+ |
+
+ @ | +
+ |
+
+ [<selectors>] | +
+ |
+
+ .name | +shorthand for ['name'] | +
+ .* | +shorthand for [*] | +
+ ..&wj;[<selectors>] | +
+ |
+
+ ..name | +shorthand for ..['name'] | +
+ ..* | +shorthand for ..[*] | +
+ 'name' | +
+ |
+
+ * | +
+ |
+
+ 3 | +
+ |
+
+ 0:100:5 | +
+ |
+
+ ?<logical-expr> | +
+ |
+
+ length(@.foo) | +
+ |
+
JSONPath | +Intended Result | +
---|---|
+ $.store.book[*].author | +the authors of all books in the store | +
+ $..author | +all authors | +
+ $.store.* | +all things in the store, which are some books and a red bicycle | +
+ $.store..price | +the prices of everything in the store | +
+ $..book[2] | +the third book | +
+ $..book[2].author | +the third book's author | +
+ $..book[2].publisher | +empty result: the third book does not have a "publisher" member | +
+ $..book[-1] | +the last book in order | +
+ $..book[0,1] $..book[:2] |
+ the first two books | +
+ $..book[?@.isbn] | +all books with an ISBN number | +
+ $..book[?@.price<10] | +all books cheaper than 10 | +
+ $..* | +all member values and array elements contained in the input value | +
Query | +Result | +Result Path | +Comment | +
---|---|---|---|
+ $ | ++ {"k": "v"} | ++ $ | +Root node | +
Escape Sequence | +Unicode Character | +Description | +
---|---|---|
+ \b | +U+0008 | +BS backspace | +
+ \t | +U+0009 | +HT horizontal tab | +
+ \n | +U+000A | +LF line feed | +
+ \f | +U+000C | +FF form feed | +
+ \r | +U+000D | +CR carriage return | +
+ \" | +U+0022 | +quotation mark | +
+ \' | +U+0027 | +apostrophe | +
+ \/ | +U+002F | +slash (solidus) | +
+ \\ | +U+005C | +backslash (reverse solidus) | +
+ \uXXXX | +see |
+ hexadecimal escape | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $.o['j j'] | ++ {"k.k": 3} | ++ $['o']['j j'] | +Named value in a nested object |
+
+ $.o['j j']&wj;['k.k'] | ++ 3 | ++ $['o']['j j']&wj;['k.k'] | +Nesting further down |
+
+ $.o["j j"]&wj;["k.k"] | ++ 3 | ++ $['o']['j j']&wj;['k.k'] | +Different delimiter in the query, unchanged Normalized Path |
+
+ $["'"]["@"] | ++ 2 | ++ $['\'']['@'] | +Unusual member names |
+
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $[*] | +
+ {"j": 1, "k": 2} [5, 3] |
+
+ $['o'] $['a'] |
+ Object values | +
+ $.o[*] | +
+ 1 2 |
+
+ $['o']['j'] $['o']['k'] |
+ Object values | +
+ $.o[*] | +
+ 2 1 |
+
+ $['o']['k'] $['o']['j'] |
+ Alternative result | +
+ $.o[*, *] | +
+ 1 2 2 1 |
+
+ $['o']['j'] $['o']['k'] $['o']['k'] $['o']['j'] |
+ Non-deterministic ordering | +
+ $.a[*] | +
+ 5 3 |
+
+ $['a'][0] $['a'][1] |
+ Array members | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $[1] | ++ "b" | ++ $[1] | +Element of array | +
+ $[-2] | ++ "a" | ++ $[0] | +Element of array, from the end | +
Condition | +start | +end | +
---|---|---|
step >= 0 | +0 | +len | +
step < 0 | +len - 1 | +-len - 1 | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $[1:3] | +
+ "b" "c" |
+
+ $[1] $[2] |
+ Slice with default step | +
+ $[5:] | +
+ "f" "g" |
+
+ $[5] $[6] |
+ Slice with no end index | +
+ $[1:5:2] | +
+ "b" "d" |
+
+ $[1] $[3] |
+ Slice with step 2 | +
+ $[5:1:-2] | +
+ "f" "d" |
+
+ $[5] $[3] |
+ Slice with negative step | +
+ $[::-1] | +
+ "g" "f" "e" "d" "c" "b" "a" |
+
+ $[6] $[5] $[4] $[3] $[2] $[1] $[0] |
+ Slice in reverse order | +
Precedence | +Operator type | +Syntax | +
---|---|---|
5 | +Grouping Function Expressions |
+
+ (...) name(...) |
+
4 | +Logical NOT | ++ ! | +
3 | +Relations | +
+ == != < <= > >= |
+
2 | +Logical AND | ++ && | +
1 | +Logical OR | ++ || | +
Comparison | +Result | +Comment | +
---|---|---|
+ $.absent1 == $.absent2 | +true | +Empty nodelists | +
+ $.absent1 <= $.absent2 | +true | ++ == implies <= | +
+ $.absent == 'g' | +false | +Empty nodelist | +
+ $.absent1 != $.absent2 | +false | +Empty nodelists | +
+ $.absent != 'g' | +true | +Empty nodelist | +
+ 1 <= 2 | +true | +Numeric comparison | +
+ 1 > 2 | +false | +Numeric comparison | +
+ 13 == '13' | +false | +Type mismatch | +
+ 'a' <= 'b' | +true | +String comparison | +
+ 'a' > 'b' | +false | +String comparison | +
+ $.obj == $.arr | +false | +Type mismatch | +
+ $.obj != $.arr | +true | +Type mismatch | +
+ $.obj == $.obj | +true | +Object comparison | +
+ $.obj != $.obj | +false | +Object comparison | +
+ $.arr == $.arr | +true | +Array comparison | +
+ $.arr != $.arr | +false | +Array comparison | +
+ $.obj == 17 | +false | +Type mismatch | +
+ $.obj != 17 | +true | +Type mismatch | +
+ $.obj <= $.arr | +false | +Objects and arrays do not offer < comparison | +
+ $.obj < $.arr | +false | +Objects and arrays do not offer < comparison | +
+ $.obj <= $.obj | +true | ++ == implies <= | +
+ $.arr <= $.arr | +true | ++ == implies <= | +
+ 1 <= $.arr | +false | +Arrays do not offer < comparison | +
+ 1 >= $.arr | +false | +Arrays do not offer < comparison | +
+ 1 > $.arr | +false | +Arrays do not offer < comparison | +
+ 1 < $.arr | +false | +Arrays do not offer < comparison | +
+ true <= true | +true | ++ == implies <= | +
+ true > true | +false | +Booleans do not offer < comparison | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $.a[?@.b == 'kilo'] | ++ {"b": "kilo"} | ++ $['a'][9] | +Member value comparison | +
+ $.a[?(@.b == 'kilo')] | ++ {"b": "kilo"} | ++ $['a'][9] | +Equivalent query with enclosing parentheses | +
+ $.a[?@>3.5] | +
+ 5 4 6 |
+
+ $['a'][1] $['a'][4] $['a'][5] |
+ Array value comparison | +
+ $.a[?@.b] | +
+ {"b": "j"} {"b": "k"} {"b": {}} {"b": "kilo"} |
+
+ $['a'][6] $['a'][7] $['a'][8] $['a'][9] |
+ Array value existence | +
+ $[?@.*] | +
+ [3, 5, 1, 2, 4, 6, {"b": "j"}, {"b": "k"}, {"b": {}}, {"b": "kilo"}] {"p": 1, "q": 2, "r": 3, "s": 5, "t": {"u": 6}} |
+
+ $['a'] $['o'] |
+ Existence of non-singular queries | +
+ $[?@[?@.b]] | ++ [3, 5, 1, 2, 4, 6, {"b": "j"}, {"b": "k"}, {"b": {}}, {"b": "kilo"}] | ++ $['a'] | +Nested filters | +
+ $.o[?@<3, ?@<3] | +
+ 1 2 2 1 |
+
+ $['o']['p'] $['o']['q'] $['o']['q'] $['o']['p'] |
+ Non-deterministic ordering | +
+ $.a[?@<2 || @.b == "k"] | +
+ 1 {"b": "k"} |
+
+ $['a'][2] $['a'][7] |
+ Array value logical OR | +
+ $.a[?match(@.b, "[jk]")] | +
+ {"b": "j"} {"b": "k"} |
+
+ $['a'][6] $['a'][7] |
+ Array value regular expression match | +
+ $.a[?search(@.b, "[jk]")] | +
+ {"b": "j"} {"b": "k"} {"b": "kilo"} |
+
+ $['a'][6] $['a'][7] $['a'][9] |
+ Array value regular expression search | +
+ $.o[?@>1 && @<4] | +
+ 2 3 |
+
+ $['o']['q'] $['o']['r'] |
+ Object value logical AND | +
+ $.o[?@>1 && @<4] | +
+ 3 2 |
+
+ $['o']['r'] $['o']['q'] |
+ Alternative result | +
+ $.o[?@.u || @.x] | ++ {"u": 6} | ++ $['o']['t'] | +Object value logical OR | +
+ $.a[?@.b == $.x] | +
+ 3 5 1 2 4 6 |
+
+ $['a'][0] $['a'][1] $['a'][2] $['a'][3] $['a'][4] $['a'][5] |
+ Comparison of queries with no values | +
+ $.a[?@ == @] | +
+ 3 5 1 2 4 6 {"b": "j"} {"b": "k"} {"b": {}} {"b": "kilo"} |
+
+ $['a'][0] $['a'][1] $['a'][2] $['a'][3] $['a'][4] $['a'][5] $['a'][6] $['a'][7] $['a'][8] $['a'][9] |
+ Comparisons of primitive and of structured values | +
Type | +Instances | +
---|---|
+ ValueType | +JSON values or Nothing | +
+ LogicalType | ++ LogicalTrue or LogicalFalse | +
+ NodesType | +Nodelists | +
Query | +Comment | +
---|---|
+ $[?length(@) < 3] | +well-typed | +
+ $[?length(@.*) < 3] | +not well-typed since @.* is a non-singular query | +
+ $[?count(@.*) == 1] | +well-typed | +
+ $[?count(1) == 1] | +not well-typed since 1 is not a query or function expression | +
+ $[?count(foo(@.*)) == 1] | +well-typed, where foo() is a function extension with a parameter of type NodesType and result type NodesType | +
+ $[?match(@.timezone, 'Europe/.*')] | +well-typed | +
+ $[?match(@.timezone, 'Europe/.*') == true] | +not well-typed as LogicalType may not be used in comparisons | +
+ $[?value(@..color) == "red"] | +well-typed | +
+ $[?value(@..color)] | +not well-typed as ValueType may not be used in a test expression | +
+ $[?bar(@.a)] | +well-typed for any function bar() with a parameter of any declared type and result type LogicalType | +
+ $[?bnl(@.*)] | +well-typed for any function bnl() with a parameter of declared type NodesType or LogicalType and result type LogicalType | +
+ $[?blt(1==1)] | +well-typed, where blt() is a function with a parameter of declared type LogicalType and result type LogicalType | +
+ $[?blt(1)] | +not well-typed for the same function blt(), as 1 is not a query, logical-expr, or function expression | +
+ $[?bal(1)] | +well-typed, where bal() is a function with a parameter of declared type ValueType and result type LogicalType | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $[0, 3] | +
+ "a" "d" |
+
+ $[0] $[3] |
+ Indices | +
+ $[0:2, 5] | +
+ "a" "b" "f" |
+
+ $[0] $[1] $[5] |
+ Slice and index | +
+ $[0, 0] | +
+ "a" "a" |
+
+ $[0] $[0] |
+ Duplicated entries | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $..j | +
+ 1 4 |
+
+ $['o']['j'] $['a'][2][0]['j'] |
+ Object values | +
+ $..j | +
+ 4 1 |
+
+ $['a'][2][0]['j'] $['o']['j'] |
+ Alternative result | +
+ $..[0] | +
+ 5 {"j": 4} |
+
+ $['a'][0] $['a'][2][0] |
+ Array values | +
+ $..[*] or $..* |
+
+ {"j": 1, "k": 2} [5, 3, [{"j": 4}, {"k": 6}]] 1 2 5 3 [{"j": 4}, {"k": 6}] {"j": 4} {"k": 6} 4 6 |
+
+ $['o'] $['a'] $['o']['j'] $['o']['k'] $['a'][0] $['a'][1] $['a'][2] $['a'][2][0] $['a'][2][1] $['a'][2][0]['j'] $['a'][2][1]['k'] |
+ All values | +
+ $..o | ++ {"j": 1, "k": 2} | ++ $['o'] | +Input value is visited | +
+ $.o..[*, *] | +
+ 1 2 2 1 |
+
+ $['o']['j'] $['o']['k'] $['o']['k'] $['o']['j'] |
+ Non-deterministic ordering | +
+ $.a..[0, 1] | +
+ 5 3 {"j": 4} {"k": 6} |
+
+ $['a'][0] $['a'][1] $['a'][2][0] $['a'][2][1] |
+ Multiple segments | +
Query | +Result | +Result Paths | +Comment | +
---|---|---|---|
+ $.a | ++ null | ++ $['a'] | +Object value | +
+ $.a[0] | ++ | + | + null used as array | +
+ $.a.d | ++ | + | + null used as object | +
+ $.b[0] | ++ null | ++ $['b'][0] | +Array value | +
+ $.b[*] | ++ null | ++ $['b'][0] | +Array value | +
+ $.b[?@] | ++ null | ++ $['b'][0] | +Existence | +
+ $.b[?@==null] | ++ null | ++ $['b'][0] | +Comparison | +
+ $.c[?@.d==null] | ++ | + | Comparison with "missing" value | +
+ $.null | ++ 1 | ++ $['null'] | +Not JSON null at all, just a member name string | +
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 | +
Function Name | +Brief Description | +Parameters | +Result | +
---|---|---|---|
length | +length of string, array, or object | ++ ValueType | ++ ValueType | +
count | +size of nodelist | ++ NodesType | ++ ValueType | +
match | +regular expression full match | ++ ValueType, ValueType | ++ LogicalType | +
search | +regular expression substring match | ++ ValueType, ValueType | ++ LogicalType | +
value | +value of the single node in nodelist | ++ NodesType | ++ ValueType | +
XPath | +JSONPath | +Description | +
---|---|---|
+ / | ++ $ | +the root XML element | +
+ . | ++ @ | +the current XML element | +
+ / | ++ . or [] | +child operator | +
+ .. | +n/a | +parent operator | +
+ // | ++ ..name, ..&wj;[index], ..*, or ..[*] | +descendants (JSONPath borrows this syntax from E4X) | +
+ * | ++ * | +wildcard: All XML elements regardless of their names | +
+ @ | +n/a | +attribute access: JSON values do not have attributes | +
+ [] | ++ [] | +subscript operator used to iterate over XML element collections and for predicates | +
+ | | ++ [,] | +Union operator (results in a combination of node sets); called list operator in JSONPath, allows combining member names, array indices, and slices | +
n/a | ++ [start:end:step] | +array slice operator borrowed from ES4 | +
+ [] | ++ ? | +applies a filter (script) expression | +
seamless | +n/a | +expression engine | +
+ () | +n/a | +grouping | +
XPath | +JSONPath | +Result | +
---|---|---|
+ /store/book/author | ++ $.store.book[*].author | +the authors of all books in the store | +
+ //author | ++ $..author | +all authors | +
+ /store/* | ++ $.store.* | +all things in store, which are some books and a red bicycle | +
+ /store//price | ++ $.store..price | +the prices of everything in the store | +
+ //book[3] | ++ $..book[2] | +the third book | +
+ //book[last()] | ++ $..book[-1] | +the last book in order | +
+ //&wj;book[position()<3] | +
+ $..book[0,1] $..book[:2] |
+ the first two books | +
+ //book[isbn] | ++ $..book[?@.isbn] | +filter all books with an ISBN number | +
+ //book[price<10] | ++ $..book[?@.price<10] | +filter all books cheaper than 10 | +
+ //* | ++ $..* | +all elements in an XML document; all member values and array elements contained in input value | +