JSONPath queries
A JSONPath query selects nodes by their position in the document, for example every email field of every user, or the books cheaper than 10. Unlike a filter query, it can return any node, at any depth: objects, arrays, or single values.
JSONPath works on JSON files. To query an NDJSON file, use jq or SQL.
Run a JSONPath query
Section titled “Run a JSONPath query”-
Press Ctrl+Shift+J, or choose Search → JSONPath Query…. The query bar opens on the JSONPath tab.
-
Type an expression that starts with
$, the root of the document, for example:$.store.books[?@.price < 10].title -
Press Enter.
The tree goes to the first result, and the query bar shows your position, for example 1 of 4. If the expression is not valid, the query bar shows Error; hover over it to read what is wrong.
Common expressions
Section titled “Common expressions”| Expression | Selects |
|---|---|
$.users[0] |
The first element of users |
$.users[-1] |
The last element of users |
$.users[*].email |
The email of every user |
$..email |
Every email field, at any depth |
$.users[?@.age > 30] |
The users older than 30 |
$.users[?@.active == true].name |
The names of the active users |
$.items[0:10] |
The first ten items |
For the full syntax, see JSONPath.
Step through results
Section titled “Step through results”Press Enter or select the down arrow for the next result, and Shift+Enter or the up arrow for the previous one. Each result is selected in the tree, so the Properties panel and the node commands, such as Copy Path, act on it.
To copy every result as JSON, select Copy matched objects as JSON. For the other controls of the query bar, see Use the query bar.
A JSONPath query fails on a very large document with “Subtree too large to query in memory”. For such a file, use a filter query or SQL instead; see Limits.