By Mian Ali Khalid · Published · How we build and test tools
How to use the jsonpath
- Paste your JSON data into the JSON input field.
- Type a JSONPath expression starting with
$, such as$.store.book[*].title. - The results update automatically, showing each matched value alongside its full path.
- Use filters like
[?(@.price < 10)]to narrow down results based on conditions.
Supported JSONPath syntax
This jsonpath evaluator implements a practical subset of the JSONPath specification. Every expression must begin with $, which represents the root of the JSON document.
| Syntax | Description | Example |
|---|---|---|
.key | Dot notation for object properties | $.store.name |
['key'] | Bracket notation, supports multiple keys | $['store','warehouse'] |
[n] | Array index (zero-based, negative from end) | $.books[0] |
[*] | Wildcard: all elements in an array or object | $.store.* |
[start:end:step] | Array slice, similar to Python slicing | $[1:4:2] |
..key | Recursive descent through all descendants | $..author |
[?(@.k op v)] | Filter expression with comparison operators | $[?(@.price < 10)] |
Also supported: unions such as $..book[0,1] or $['a','b'], and recursive descent before a bracket selector ($..[0], $..*). Not supported, and reported as an error: regular expressions (=~), arithmetic or script expressions, filter functions such as length() or match(), wildcards or filters inside a filter path, and the parent (^) and property-name (~) operators. Numbers are read as ordinary floating point values, so integers beyond 2^53 may be rounded in the result.
How filter expressions work
Filter expressions let you select array elements or object members that satisfy a condition. The syntax is [?(@.property operator value)]. The @ symbol refers to the current element being evaluated.
For example, given an array of books, the jsonpath expression $[?(@.price < 10)] returns every book object where the price property is less than 10. Supported operators are ==, !=, <, <=, > and >=, combined with &&, ||, ! and parentheses, for example [?(@.price < 10 && @.category == 'fiction')]. A filter can also compare against the document root, such as @.price < $.expensive, and @.length works on arrays and strings.
Comparisons are strict: 1 and "1" are different values, and < or > only match when both sides are numbers or both are strings (strings compare by code unit order). A missing property never matches ==, < or >, but it does match !=. You can also filter by existence alone using [?(@.isbn)], which matches any element that has an isbn property regardless of its value.
Array slicing explained
Array slicing uses the format [start:end:step], following the same conventions as Python. All three parameters are optional. If omitted, start defaults to 0, end defaults to the array length, and step defaults to 1.
Negative indices count from the end of the array. For instance, $[-2:] selects the last two elements. A negative step reverses the traversal direction: $[::-1] returns the entire array in reverse order.
Consider the array [10, 20, 30, 40, 50]. The expression $[1:4] yields [20, 30, 40]. Adding a step of 2 with $[0:5:2] produces [10, 30, 50]. Slices never throw out-of-bounds errors; they simply return whatever elements fall within the computed range.
Practical use cases
Querying JSON data is common when working with REST APIs, configuration files or log entries. Instead of writing custom JavaScript to traverse nested structures, a jsonpath expression extracts exactly what you need in a single line.
Developers often use this approach to inspect large API responses. Rather than scrolling through thousands of lines of formatted output (which tools like the JSON formatter help with), you can target specific fields. If you later need to convert extracted data to other formats, sibling tools handle transformations such as json to xml or json to sql.
Data engineers use recursive descent (..) to find all occurrences of a key at any depth, which is helpful when normalizing inconsistent schemas. Filter expressions replace manual loops when you only need records matching certain criteria, such as active users or transactions above a threshold.
Common mistakes and edge cases
The most frequent error is forgetting the leading $. Every valid jsonpath expression must start with the root selector. Another common issue is mixing up dot notation and bracket notation for keys containing spaces or special characters. Use $['my key'] instead of $.my key when property names include spaces, hyphens or reserved characters.
Unicode is fully supported in both property names and string values. An expression like $.café.menu works correctly as long as the JSON input contains that exact key. Empty strings, null values and empty arrays are valid JSON and handled properly: querying an empty array with $[*] simply returns no matches.
If your JSON input is malformed, the parser reports the exact position of the syntax error. Consider running it through a JSON fixer first if you encounter persistent parse failures. Very deeply nested documents may take slightly longer to evaluate with recursive descent, but typical API payloads process instantly.
Worked examples
| Example | Input | Result |
|---|---|---|
| All book titles | JSON input: {"store":{"book":[{"title":"A","price":10},{"title":"B","price":5}]}}; JSONPath expression: $.store.book[*].title | $.store.book[0].title: "A"; $.store.book[1].title: "B" |
| Books under 8 | JSON input: {"store":{"book":[{"title":"A","price":10},{"title":"B","price":5}]}}; JSONPath expression: $.store.book[?(@.price < 8)] | $.store.book[1]: {"title":"B","price":5} |
| First two items | JSON input: [10, 20, 30, 40]; JSONPath expression: $[0:2] | $[0]: 10; $[1]: 20 |
FAQ
What is JSONPath?
JSONPath is a query language for JSON, similar to how XPath works for XML. It lets you navigate through a JSON structure and extract specific values using concise expressions that describe the path to the data you need.
Is my JSON data sent to a server?
No. This jsonpath evaluator runs entirely in your browser. Your JSON input and queries never leave your device, making it safe to use with sensitive or proprietary data.
Can I use regular expressions in filters?
This implementation supports standard comparison operators (==, !=, <, <=, >, >=) and existence checks. Regular expression matching inside filter expressions is not currently supported to keep evaluation predictable and fast.
How do I access array elements from the end?
Use negative indices in bracket notation. For example, $[-1] returns the last element of an array, and $[-2] returns the second-to-last element.
What happens if a path does not match anything?
If the expression is syntactically valid but matches no elements in the provided JSON, the tool displays an empty result set rather than an error. This helps distinguish between a bad query and a query that simply found nothing.
Does this support union of keys?
Yes. You can specify multiple property names in bracket notation separated by commas, such as $['name','age'], to retrieve several fields from the same object level simultaneously. Numeric unions such as $[0,2] and slices inside a union also work.