JSON Path Tester
A tool to test JSONPath expressions and extract desired values from JSON data. An essential tool for API response parsing and data analysis!
Result will appear here...
Common Patterns
Root
$Root object
All Books
$.store.book[*]All books in store
First Book
$.store.book[0]First book
Last Book
$.store.book[-1]Last book
Book Titles
$.store.book[*].titleAll book titles
Books < $10
$.store.book[?(@.price < 10)]Books cheaper than $10
Books with ISBN
$.store.book[?(@.isbn)]Books with ISBN
All Prices
$.store..priceAll prices (recursive)
Syntax Guide:
$- Root object@- Current object.or[]- Child operator..- Recursive descent*- Wildcard[start:end]- Array slice[?(<expr>)]- Filter expression
What is JSONPath?
JSONPath is an expression language for querying values in JSON data structures. Just like XPath does for XML, JSONPath allows you to extract specific data from JSON.
Key Syntax
Basic Operators
| Operator | Description | Example |
|---|---|---|
$ | Root object | $ |
@ | Current object (inside filter) | @.price |
. or [] | Child element | $.store.book |
.. | Recursive search | $..price |
* | Wildcard | $.store.* |
[n] | Array index | $.store.book[0] |
[start:end] | Array slice | $.store.book[0:2] |
[?(<expr>)] | Filter expression | $..book[?(@.price < 10)] |
Array Indexing
// First element
$.store.book[0]
// Last element
$.store.book[-1]
// Range (from 0 to before index 2)
$.store.book[0:2]
// All elements
$.store.book[*]
Filter Expressions
// Books with price less than 10
$.store.book[?(@.price < 10)]
// Books that have ISBN
$.store.book[?(@.isbn)]
// Books in fiction category
$.store.book[?(@.category === 'fiction')]
// Books with specific word in title
$.store.book[?(@.title.includes('Moby'))]
Practical Examples
Extracting Data from API Response
// API response
{
"users": [
{ "id": 1, "name": "John", "active": true },
{ "id": 2, "name": "Jane", "active": false },
{ "id": 3, "name": "Bob", "active": true }
]
}
// Extract only active users
$.users[?(@.active === true)]
// All user names
$.users[*].name
Navigating Nested Data
// Complex JSON
{
"company": {
"departments": [
{
"name": "Engineering",
"employees": [
{ "name": "Alice", "salary": 100000 },
{ "name": "Bob", "salary": 90000 }
]
},
{
"name": "Sales",
"employees": [
{ "name": "Charlie", "salary": 80000 }
]
}
]
}
}
// All employee salaries
$..employees[*].salary
// Employees with salary >= 90000
$..employees[?(@.salary >= 90000)]
Processing Array Data
// E-commerce data
{
"products": [
{ "name": "Laptop", "price": 1000, "stock": 5 },
{ "name": "Mouse", "price": 20, "stock": 0 },
{ "name": "Keyboard", "price": 50, "stock": 10 }
]
}
// Products in stock
$.products[?(@.stock > 0)]
// Price range (20 ~ 100)
$.products[?(@.price >= 20 && @.price <= 100)]
Use Cases
1. API Testing and Debugging
// Extract error messages from GraphQL response
$.errors[*].message
// REST API pagination data
$.data.items[*]
2. Data Analysis
// Filter data by specific conditions
$..transactions[?(@.amount > 1000)]
// Collect statistical data
$..metrics[*].value
3. Configuration File Parsing
// Extract specific environment configuration
$.environments[?(@.name === 'production')]
// Enabled feature flags
$.features[?(@.enabled === true)].name
4. Log Analysis
// Filter error logs only
$.logs[?(@.level === 'error')]
// Logs within specific time range
$.logs[?(@.timestamp > 1234567890)]
Comparison Operators
Available operators in JSONPath filters:
===- Equal!==- Not equal<- Less than<=- Less than or equal>- Greater than>=- Greater than or equal&&- AND||- OR
Usage Tips
1. Step-by-Step Testing
Test complex paths by breaking them down:
// Step 1: $.store
// Step 2: $.store.book
// Step 3: $.store.book[*]
// Step 4: $.store.book[*].title
2. Using Recursive Search
Use .. when structure is unknown:
// Find all price fields
$..price
3. Combining Filters
Combine multiple conditions:
$..book[?(@.price < 10 && @.category === 'fiction')]
Important Notes
- JSONPath expressions are case-sensitive
- Use
@to reference the current object inside filter expressions - Array slicing works similarly to Python (start inclusive, end exclusive)
- Syntax may vary slightly between different implementations
Related Tools
- JSON Formatter - JSON formatting
- API Tester - API testing
- Regex Tester - Regular expression testing
Additional Resources
- JSONPath Official Documentation
- JSONPath Plus - Library in use