In order to parse JSON structures, we use JSONPath. JSONPath is the XPath for JSON; it's used to refer to JSON elements in the same way as XPath is used for XML elements.
JSONPath expressions use dot notation, as in $.store.book[0].title.
The following table shows a basic overview of the JSONPath syntax elements. The examples refer to the book's structure presented earlier:
JSONPath expression |
Description |
Sample |
$ |
Root object |
$ returns the whole JSON structure |
. |
Child operator; it's used to access different levels of the JSON structure |
$..title returns the titles of the books |
* |
Wildcard for referring to all elements |
$.store.book.* returns all books |
[] |
Array ... |