JSONPath Tester
Test JSONPath expressions on JSON data
JSONPath is a query language for extracting data from JSON documents — like XPath for XML. Navigate nested objects and arrays without code.
What is JSONPath?
JSONPath is a query language for extracting specific values from JSON documents. It provides a concise syntax for navigating nested objects and arrays, filtering elements by conditions, and selecting multiple values at once — all without writing procedural code.
Think of JSONPath as the JSON equivalent of XPath for XML, or CSS selectors for HTML. Instead of writing loops and conditional statements to traverse a JSON tree, you write a single expression that describes the data you want. The JSONPath engine handles the traversal and returns the matching values.
JSONPath is especially valuable when working with API responses. Modern APIs often return deeply nested JSON structures — a single response might contain dozens of nested objects and arrays. JSONPath lets you surgically extract the fields you need without manually navigating every level of nesting.
JSONPath Syntax
Every JSONPath expression starts with $, which represents the root of the JSON document. From there, you chain operators to navigate deeper into the structure.
Syntax Reference
| Operator | Description | Example |
|---|---|---|
$ | Root object | $ returns the entire document |
.key | Child member | $.store accesses the store property |
..key | Recursive descent | $..price finds all price fields at any depth |
[0] | Array index | $.books[0] returns the first book |
[*] | Wildcard | $.books[*] returns all books |
[0:3] | Array slice | $.books[0:3] returns books at index 0, 1, 2 |
[?(@.price<10)] | Filter | Returns elements where condition is true |
@ | Current element | Used inside filter expressions |
Navigating Objects
Dot notation (.key) accesses a named property of the current object. You can chain dots to traverse multiple levels:
$.store.address.city
This navigates from root → store → address → city. If any intermediate key does not exist, the result is empty.
Navigating Arrays
Array elements are accessed by zero-based index ([0], [1], etc.) or by wildcard ([*] for all elements). Negative indices count from the end: [-1] returns the last element.
Array slicing follows the [start:end:step] pattern, similar to Python:
[0:3]— Elements at indices 0, 1, 2[1:]— All elements from index 1 onward[::2]— Every other element
Recursive Descent
The .. operator searches recursively through the entire document tree. $..price finds every property named price, regardless of how deeply it is nested. This is powerful but can be slow on large documents because it traverses every node.
Filter Expressions
Filters use the syntax [?(@.condition)] where @ refers to the current element. Filters support comparison operators (==, !=, <, >, <=, >=) and logical operators (&&, ||).
Examples:
$.books[?(@.price < 10)]— Books cheaper than 10$.books[?(@.author == 'Tolkien')]— Books by Tolkien$.books[?(@.price < 20 && @.category == 'fiction')]— Cheap fiction books
JSONPath Tree Traversal
JSONPath vs jq
While JSONPath and jq both query JSON, they serve different contexts:
| Feature | JSONPath | jq |
|---|---|---|
| Environment | Libraries, browsers, APIs | Command line |
| Syntax style | Dot notation ($.store.books) | Pipe-based (.store.books) |
| Transformation | Read-only (query) | Read + transform + construct |
| Complexity | Simple queries | Complex data pipelines |
| Standard | RFC 9535 (2024) | De facto CLI standard |
| Best for | API testing, config queries | Log processing, data pipelines |
JSONPath is ideal when you need to extract data from JSON without transforming it — for example, testing API responses or building config queries. jq is more powerful when you need to reshape, filter, aggregate, or construct new JSON structures.
Common Use Cases
- API debugging: Paste a complex API response and write JSONPath queries to validate that expected fields exist and contain correct values
- Configuration extraction: Pull specific values from large JSON config files without parsing the entire structure in code
- Test assertions: Automated tests use JSONPath to assert specific values in API responses, making test code more readable than nested property access
- Data transformation pipelines: Extract specific fields from JSON documents as part of ETL workflows
- Documentation: JSONPath expressions in API docs show consumers exactly how to access specific response fields
Try These Examples
This JSONPath expression navigates to the 'store' object, filters the 'books' array for items where price is less than 10, and returns only the 'title' field. The @ symbol refers to the current element being evaluated.
$.store.books[?(@.price < 10)].title Querying a path that does not exist in the JSON document returns an empty result set — not an error. This is useful for safely checking whether a key exists without crashing.
$.nonexistent