Online JSONPath Query Tool: Extract Data from JSON Structures
What Is JSONPath
JSONPath is a query language for extracting information from JSON data structures, similar to XPath for XML. It uses path expressions to locate and extract specific data from JSON — pair it with a JSON Formatter to make nested structures easier to read before querying.
Basic Syntax
| Expression | Description | Example |
|------------|-------------|---------|
| $ | Root node | $ |
| . | Child node | $.name |
| [] | Child node/filter | $['name'] |
| * | Wildcard | $.* |
| .. | Recursive search | $..name |
| @ | Current node | $.users[?(@.age>25)] |
Why You Need JSONPath
- API data extraction: Precisely extract needed fields from complex API responses
- Data transformation: Extract and restructure nested JSON data
- Log analysis: Filter specific info from structured logs
- Config management: Read specific values from multi-level config files
- Test assertions: Verify specific field values in API testing
- Data migration: Map fields between different data structures
JSONPath Expressions Explained
Sample JSON Data
{
"store": {
"books": [
{ "title": "JavaScript: The Definitive Guide", "price": 99, "category": "Programming" },
{ "title": "CSS: The Definitive Guide", "price": 79, "category": "Frontend" },
{ "title": "HTTP: The Definitive Guide", "price": 89, "category": "Networking" }
],
"bicycle": { "color": "red", "price": 299 }
}
}
Common Expressions
| JSONPath | Result |
|----------|--------|
| $.store.books[*].title | All book titles |
| $.store.books[0] | First book |
| $.store.books[-1] | Last book |
| $.store.books[?(@.price<85)] | Books under $85 |
| $.store.books[?(@.category=='Frontend')].title | Frontend book titles |
| $.store..price | All prices |
| $.store.books.length() | Number of books |
How to Use an Online Tool
Using ToolVault's JSONPath Query Tool:
- Paste JSON data
- Enter JSONPath expression
- Real-time query results
- Syntax highlighting and error detection
- Built-in expression templates
JSONPath in Code
JavaScript
// Simple JSONPath implementation
function jsonPath(obj, path) {
const keys = path.replace(/\$/,'').replace(/\[(\d+)\]/g, '.$1').split('.').filter(Boolean);
return keys.reduce((current, key) => current?.[key], obj);
}
// Usage
const data = { store: { books: [{ title: 'JS Guide', price: 99 }] } };
const title = jsonPath(data, '$.store.books[0].title'); // 'JS Guide'
Python
from jsonpath_ng import parse
expression = parse('$.store.books[?(@.price<90)]')
matches = expression.find(data)
for match in matches:
print(match.value)
JSONPath vs JSON Pointer
| Feature | JSONPath | JSON Pointer |
|---------|----------|-------------|
| Syntax | XPath-like | URL path-like |
| Filtering | ✅ Supports conditions | ❌ No |
| Wildcards | ✅ Supported | ❌ No |
| Recursive search | ✅ .. syntax | ❌ No |
| Standard | Community standard | RFC 6901 |
| Use case | Complex queries | Simple lookup |
FAQ
Is There a Standard for JSONPath?
JSONPath has no official RFC standard yet, but there's a widely accepted community standard. Different language implementations may have minor differences, but core syntax is consistent.
How to Handle Chinese Characters in JSONPath?
JSONPath expressions support Unicode natively — you can use Chinese key names directly: $.data['中文键名']. However, English key names are recommended to avoid encoding issues.
How Is JSONPath Query Performance?
Performance depends on expression complexity and data structure. Simple path queries ($.data[0].name) are fast. Recursive searches (..) may be slower on deeply nested data. Cache results at the application layer for repeated queries.
This article is brought to you by ToolVault. More developer tools at the homepage.
Related Tools
Related Articles
HTML Table to JSON: How to Preserve Rows, Columns and Structure
Converting an HTML table from a web page to JSON — how to keep headers, handle merged cells and nested structure? Step-by-step with our HTML table to JSON tool.
Excel to JSON: Dates Become Numbers / Chinese Garbled — Fix
When converting Excel to JSON, dates turn into numbers like 44927, Chinese is garbled, empty cells vanish? Explains Excel serial dates and encoding pitfalls, with our Excel to JSON tool.
The Complete Guide to Table Format Conversion: Excel, CSV, JSON, Markdown, and HTML
A full walkthrough of converting between Excel, CSV, JSON, Markdown, and HTML tables: format characteristics, conversion paths, hands-on workflows, and common pitfalls — 12 free online converters in one place.