...
XPath | JSONPath | Description |
/ | $ | The base node in the object. |
. | @ | The current object in the node path. |
/ | . or [] | Accessing a child node, or specific child node |
.. | n/a | Accessing the parent of the current node. |
// | .. | Recursive child decent. |
* | * | Wildcard operator to access any node. |
@ | n/a | Accessing an attribute. |
[] | [] | Accessing an element within a list of nodes. |
| | [,] | Union of two sets of nodes. |
n/a | [start:end:step] | Accessing elements as a slice of a set of elements. |
[] | ?() | Accessing nodes with a filter applied. |
...
Listed below is an example response in JSON and XML.
|
---|
...
...
|
|
---|
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 price of everything in the store. |
//book[3] | $..book[2] | the third book |
//book[last()] | $..book[(@.length-1)] $..book[-1:] | the last book in order. |
//book[position()<3] | $..book[0,1] $..book[:2] | the first two books |
//book[isbn] | $..book[?(@.isbn)] | filter all books with isbn number |
//book[price<10] | $..book[?(@.price<10)] | filter all books cheapier than 10 |
//* | $..* | all Elements in XML document. All members of JSON structure. |
...