JSONPath Evaluator
Query JSON documents with JSONPath expressions and preview matched values.
What this tool does
JSONPath is a query language for JSON documents, similar to how XPath works for XML. It allows you to extract specific values from complex JSON structures using a compact path notation. This tool evaluates JSONPath expressions against sample JSON and shows the matched values, with support for filters, recursive descent, wildcards, and array slicing.
The expression $ represents the root document. .property accesses a named field, [n] accesses the nth element of an array, .. performs recursive descent (searches all descendants), and ?() applies a filter expression. This is invaluable for exploring large API responses, extracting data from complex configurations, and testing JSONPath queries before using them in code.
Usage Example
// Sample JSON
{
"store": {
"book": [
{ "title": "Sayings", "price": 8.95 },
{ "title": "Sword", "price": 12.99 },
{ "title": "Moby Dick", "price": 8.99 }
]
}
}
// JSONPath expressions
$.store.book[0].title // "Sayings"
$.store.book[*].title // All titles
$.store.book[?(@.price < 10)] // Books under $10
$..price // All prices anywhere
$.store.book[-1:] // Last bookCommon Edge Cases
- Filter expressions (?(@.price < 10)) use @ to refer to the current node. The comparison operators are standard: <, >, <=, >=, ==, !=.
- Recursive descent (..) is powerful but slow on large documents. Use named paths when possible for better performance.
- Array slicing [start:end:step] is zero-indexed and supports negative indices. [::-1] reverses the array, [::2] takes every other element.
- Some JSONPath implementations differ in support for features like filter expressions, slicing, and scripts. Always check the documentation for your specific implementation.
- Wildcard (*) matches all elements at the current level. Use ..* for recursive wildcard, which finds all leaf values in the document.
FAQ
- What is the difference between $.a and $..a?
- $.a finds a field named 'a' that is a direct child of the root. $..a finds any field named 'a' anywhere in the document, including nested objects and arrays. The latter is slower but more flexible for unstructured data.
- Is JSONPath standardized?
- No. There is no formal RFC or standard for JSONPath, and implementations vary. The most common variants are Stefan Gössner's original proposal and Jayway's implementation (used in Java, JavaScript, and many testing tools).
- Can I use JSONPath in JavaScript?
- Yes. Libraries like jsonpath-plus, jsonpath, and JMESPath provide JSONPath support in JavaScript. JMESPath is a different but related query language with stronger typing and more features.