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[(@.length-1)] | Last book (script form — see pitfalls below) |
$.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 (not supported by every engine) |
Note: the
[-1]negative index silently returns an empty array in jsonpath-plus (this tool's engine) instead of erroring. Use the script expression[(@.length-1)]for the last element.length()is likewise unsupported by jsonpath-plus — dialect differences are covered below.
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
- Empty expressions error out explicitly; stray leading/trailing whitespace is trimmed — no more "path looks right but returns nothing" false negatives
Pair it with the JSONPath Generator: click tree nodes to build paths, and try the built-in expression templates (all titles / last book / price filters) — each one is verified against the actual engine in the test suite.
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 |
The five JSONPath features that vary by implementation
JSONPath has no normative spec — implementations disagree: bracket vs dot notation for keys with special characters (both valid, one often broken), filters (?(@.price < 10) — comparison operators and regex support vary wildly; in jsonpath-plus write @.name.match(/re/i) rather than =~), wildcards deep vs shallow ($..* recursion — some tools treat as all-values, others all-nodes), array slicing negative indices ([-1] — silently empty-matches in jsonpath-plus; rewrite as [(@.length-1)]), and union/section ([0,2-4] — the least portable feature). The practical rule: core paths (dot navigation, simple wildcards, single indices) work everywhere; filters and unions are dialect. When a query "works in the tester but not in production", the tester and production are running different JSONPath dialects — name the implementation (Jayway, Goessner, jsonpath-plus) before copying queries.
Filters beyond simple comparison: what power actually looks like
The filter syntax everyone learns first (?(@.price < 10)) barely scratches it: existence checks (?(@.discount) — has the field), nested path filters (?(@.address.city == "Berlin")), boolean composition (?(@.a > 1 && @.b < 5) — &&/|| support varies), and regex matching (?(@.name.match(/smith.*/i)) in jsonpath-plus — the least portable). The pattern worth internalizing: filters apply within the path context — $.orders[?(@.paid)] filters orders, $.orders[?(@.paid)].items then navigates inside survivors. Debugging trick when a filter returns nothing: run the path without the filter first — if the pre-filter result is empty, the bug is navigation, not the predicate.
Why your query returned an empty array
An empty array is JSONPath's most misleading output — it means both "the path matched nothing" and "the expression was silently swallowed by the current dialect". Debugging order:
- Run the bare path without filters (
$.store.books, not$.store.books[?(...)]) — if the bare path is empty, the bug is navigation; if bare works but filtered is empty, the bug is the predicate. - Check for stray whitespace: spaces or newlines copied in from docs or terminals make some engines silently match nothing. This tool trims them for you; trim explicitly when calling a library from code.
- Check dialect features:
[-1],length(), and=~are silent-failure or throw hotspots in jsonpath-plus; run a minimal probe before switching libraries. - Reverse-verify with the generator: click the target node in the JSONPath Generator and diff the generated path against your hand-written one — structure and spelling issues become obvious.
JSONPath vs jq vs SQL: choosing the query tool
JSONPath selects (returns sub-trees — perfect for API response extraction and test assertions); jq transforms (pipes, restructuring, arithmetic — a programming language that also selects); SQL queries (indexes, joins, aggregation — when the JSON is loaded into a database). The escalation path everyone eventually walks: JSONPath in tests → jq in shell pipelines → SQL when the data outgrew files. The mistake is jumping to the end: JSON-in-SQL with JSON_EXTRACT on every row (no indexes, full scans) is slower than jq on the same file for one-off analysis. Our JSONPath tool sits at step one — the interactive layer where learning costs seconds.
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.
The expression looks right — why does it return nothing?
Three most common causes: stray whitespace or newlines around the expression (trimmed automatically in this tool), a path that does not match the actual JSON structure (verify by clicking nodes in the JSONPath Generator), or a dialect feature the current engine does not support (e.g. jsonpath-plus has no [-1] negative index — use [(@.length-1)] instead). Empty expressions now error out explicitly rather than silently returning an empty array.
Triage notes
'Why your query returned an empty array' sits after the tutorial body because the empty array is JSONPath's most misleading output — it means both 'the path matched nothing' and 'the current dialect silently swallowed your expression'. The first triage step is deliberately the bare, filter-free path: if the bare path is empty the bug is in navigation; if it returns values and only the filtered query is empty, the problem is the predicate — one step cuts the problem space in half. The dialect section's rule is eminently practical: 'works in the tester, fails in production' means you have hit two dialects, so report the implementation name (Jayway, Goessner, jsonpath-plus) before copying the query; the tool's automatic trimming and its hard error on empty expressions are likewise aimed at reducing the 'the path was right but it returned nothing' false negatives.
Written and maintained by ToolVault. The homepage collects more browser-local tools.
Related Tools
Related Articles
Online CSV to SQL Tool: Import Tabular Data into Databases
CSV to INSERT with empty cells → NULL, MySQL backticks or PostgreSQL quotes, BOM stripping, Markdown pipe escaping, and when to switch to COPY/LOAD instead.
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.