What Is JSONPath?
JSONPath is a query language for extracting and selecting data from JSON documents. Originally proposed by Stefan Goessner in 2007 as the JSON counterpart to XPath, JSONPath is now formalized as RFC 9535. It provides a concise syntax for navigating nested JSON structures, filtering arrays, and selecting multiple values in a single expression.
JSONPath expressions always start with $ (the root element) and use a combination of dot notation, bracket notation, wildcards, and filters to drill into the data. For example, given a JSON document describing a bookstore, $.store.book[0].title returns the title of the first book, and $.store.book[?(@.price < 10)] returns all books under $10.
You’ll encounter JSONPath in REST API testing (Postman, REST Assured), Kubernetes (kubectl JSONPath output), configuration management, data pipelines, and test assertions. It’s the standard way to pinpoint values inside JSON without writing custom parsing code.
JSONPath Syntax Reference
Here’s the complete syntax this tool supports:
| Expression | Description | Example |
|---|---|---|
$ | Root element | $ — the entire document |
.property | Dot-notation child | $.store — the store object |
['property'] | Bracket-notation child | $['store'] — same as above |
[n] | Array index (0-based) | $.book[0] — first book |
[-n] | Negative index (from end) | $.book[-1] — last book |
[start:end] | Array slice | $.book[0:2] — first two books |
[start:end:step] | Slice with step | $.book[::2] — every other book |
.* or [*] | Wildcard (all children) | $.book[*].title — all titles |
..property | Recursive descent | $..price — every price at any depth |
..* | Recursive wildcard | $..* — every value in the tree |
[?(@.expr)] | Filter expression | $.book[?(@.price < 10)] — cheap books |
[a,b] | Union (multiple indices) | $.book[0,2] — first and third books |
How to Use This JSONPath Tester
- Paste your JSON document into the input area on the left.
- Type your JSONPath expression in the expression field (e.g.,
$.store.book[*].author). - Click Evaluate or press
Ctrl+Enterto run the query. - Review the results — matched values are displayed as formatted JSON, with their full paths shown for reference.
- Copy the results with the Copy button or
Ctrl+Shift+C.
The tool validates your JSON first. If the JSON is malformed, you’ll see a parse error with the position of the problem. If the JSONPath expression is invalid, you’ll see a syntax error explaining what went wrong.
Common JSONPath Expressions
These are the expressions developers use most often:
Select a single property: $.config.database.host — navigates directly to a nested value. This is the most basic and most common pattern.
Get all items in an array: $.users[*] — the wildcard [*] selects every element. Equivalent to iterating the array.
Find all values by key name: $..email — recursive descent finds every property named “email” regardless of depth. Invaluable when you know the key name but not where it lives in the structure.
Filter by value: $.products[?(@.inStock == true)] — returns only products where inStock is true. Filter expressions are the most powerful part of JSONPath.
Slice an array: $.results[0:5] — returns the first 5 elements. Useful for pagination or limiting output.
Combine selections: $.book[0,1,3] — returns the first, second, and fourth books. Union syntax selects specific indices.
Negative indexing: $.logs[-1] — returns the last element. $.logs[-3:] returns the last three.
JSONPath vs XPath vs jq
| Feature | JSONPath | XPath | jq |
|---|---|---|---|
| Data format | JSON | XML | JSON |
| Root symbol | $ | / | . |
| Recursive descent | .. | // | .. / recurse |
| Filters | [?(@.x > 5)] | [price > 5] | select(.x > 5) |
| Wildcards | * | * | .[] |
| Output | Selected values | Node sets | Transformed JSON |
| Transformation | No (read-only) | Limited (XSLT) | Full (map, reduce) |
| Standardized | RFC 9535 (2024) | W3C (1999) | No formal spec |
JSONPath is the right tool when you need to select values from JSON in a portable, standardized way — in API tests, Kubernetes, or CI/CD pipelines. Use jq when you need to transform the data (reshape, aggregate, construct new objects). Use XPath when working with XML documents.
Where JSONPath Is Used
- API testing: Postman, REST Assured, Karate, and other testing frameworks use JSONPath to assert response values.
expect(response).to.have.jsonPath('$.data.id', 42). - Kubernetes:
kubectl get pods -o jsonpath='{.items[*].metadata.name}'extracts pod names from the API response. - Data pipelines: Apache NiFi, AWS Step Functions, and Azure Logic Apps use JSONPath to extract fields from JSON payloads.
- Configuration: Spring Boot, Jayway, and other frameworks use JSONPath for dynamic configuration and property access.
- Databases: PostgreSQL’s
jsonb_path_queryand MySQL’sJSON_EXTRACTsupport JSONPath-like syntax for querying JSON columns.
Use this tool to prototype and debug your JSONPath expressions before embedding them in code, test suites, or pipeline configurations.