JSONPath Examples: Extract Values from JSON with a Path Finder
You get a 200 KB API response and only need one field, or every id in a list. Clicking through collapsed JSON in DevTools gets old fast. JSONPath lets you start at $ (the root) and walk down to the value you want.
Use the JSON Path Finder to paste JSON, enter a path, and see the result immediately. Format messy payloads first with the JSON Formatter if the structure is hard to read.
JSONPath syntax in 30 seconds
| Piece | Meaning | Example |
|---|---|---|
$ | Root of the document | $ |
.key | Child property | $.user.name |
[n] | Array index (0-based) | $.items[0] |
[*] | All items at this level | $.items[*] |
| Chaining | Combine steps | $.store.book[0].title |
Keys are case-sensitive. Use bracket notation when a key contains spaces or special characters: $["order-id"].
Sample JSON (API-style)
Use this document in the path finder while you try the examples below:
{
"status": "ok",
"user": {
"id": 42,
"profile": {
"email": "dev@example.com",
"displayName": "Alex"
}
},
"orders": [
{ "id": "A-100", "total": 19.99, "paid": true },
{ "id": "A-101", "total": 4.50, "paid": false }
],
"meta": {
"requestId": "req_8f2a",
"version": 2
}
}
Examples to copy and paste
Paste each path into the JSON Path Finder with the sample JSON above.
Root document
$
Nested email
$.user.profile.email
Result: "dev@example.com"
First order ID
$.orders[0].id
Result: "A-100"
Second order total
$.orders[1].total
Result: 4.5
Request metadata
$.meta.requestId
Result: "req_8f2a"
All orders (array wildcard)
$.orders[*]
Result: the full orders array. Useful when you want every object before filtering in code.
Status flag
$.status
Result: "ok"
Typical workflows
Debug an API response
- Copy JSON from Network tab, Postman, or
curl. - Paste into JSON Formatter if it is minified.
- Guess a path (
$.data.items[0].sku) and test it in the path finder. - If the path fails, walk up one level (
$.data.items) and inspect structure before trying again.
Compare two payloads
After extracting paths from two responses, use Compare and Diff or JSON Merge when you need to see what changed between versions.
Validate before production
If the API must match a contract, pair path checks with the JSON Schema Validator and JSON Validator so structure and types are both covered.
Common mistakes
- Wrong root. Paths must start with
$.user.emailwithout$will not behave as JSONPath. - Off-by-one indices. JSON arrays are zero-based; the first item is
[0], not[1]. - Dots in keys.
$.user-nameis wrong for keyuser-name; use$["user-name"]. - Assuming filters. Full JSONPath specs include filters like
$[?(@.price < 10)]. Many online tools focus on$,.,[], and*. Test advanced syntax before you rely on it in production. - Minified JSON typos. A missing comma breaks parsing entirely. Validate JSON first.
JSONPath vs other approaches
| Approach | Best for |
|---|---|
| JSONPath | Quick extraction, logs, ad-hoc API debugging |
jq (CLI) | Scripting and pipelines in the terminal |
JavaScript obj.a.b | Code when the shape is fixed and typed |
| JSON Schema | Enforcing allowed structure, not one-off queries |
For one field from a large response, JSONPath plus an online finder is usually the fastest loop.
When to use something else
- Transform or reshape entire documents: use code,
jq, or ETL tools, not a single path. - Highly filtered queries (e.g. all orders where
paidis false): filter in code or use an engine that supports JSONPath filters. - Non-JSON bodies: XML, CSV, or plain text need different tools.
