Last updated
JSONPath Syntax Reference
$ Root element
. Child operator (dot notation)
[] Child operator (bracket notation)
* Wildcard — all elements
.. Recursive descent — search all levels
[n] Array index (0-based)
[start:end] Array slice
[?()] Filter expression
@ Current element (in filter expressions)
Example: Array Access
// Input JSON:
{
"users": [
{ "id": 1, "name": "Alice", "role": "admin", "age": 30 },
{ "id": 2, "name": "Bob", "role": "user", "age": 25 },
{ "id": 3, "name": "Carol", "role": "user", "age": 35 },
{ "id": 4, "name": "Dave", "role": "editor", "age": 28 }
]
}
// Queries:
$.users[0] → { "id": 1, "name": "Alice", ... }
$.users[0].name → "Alice"
$.users[-1].name → "Dave" (last element)
$.users[0,2].name → ["Alice", "Carol"]
$.users[0:2].name → ["Alice", "Bob"] (slice, exclusive end)
$.users[*].name → ["Alice", "Bob", "Carol", "Dave"]
$.users.length → 4
Example: Filter Expressions
// Input JSON (same users array as above)
// Filter by role:
$.users[?(@.role == 'admin')]
→ [{ "id": 1, "name": "Alice", "role": "admin", "age": 30 }]
// Filter by age:
$.users[?(@.age > 28)]
→ [Alice (30), Carol (35)]
// Filter with multiple conditions:
$.users[?(@.age >= 28 && @.role == 'user')]
→ [Carol (35)]
// Get names of filtered users:
$.users[?(@.role == 'user')].name
→ ["Bob", "Carol"]
// Check if field exists:
$.users[?(@.email)]
→ [] (no users have email field)
Example: Recursive Descent
// Input JSON:
{
"company": {
"name": "Acme Corp",
"departments": [
{
"name": "Engineering",
"manager": { "name": "Alice", "id": 1 },
"employees": [
{ "name": "Bob", "id": 2 },
{ "name": "Carol", "id": 3 }
]
},
{
"name": "Marketing",
"manager": { "name": "Dave", "id": 4 },
"employees": [
{ "name": "Eve", "id": 5 }
]
}
]
}
}
// Find all "name" fields at any depth:
$..name
→ ["Acme Corp", "Engineering", "Alice", "Bob", "Carol", "Marketing", "Dave", "Eve"]
// Find all objects with an "id" field:
$..[?(@.id)]
→ [Alice, Bob, Carol, Dave, Eve]
// Find all IDs:
$..id
→ [1, 2, 3, 4, 5]
Example: Complex API Response
// Input: GitHub repository search response
{
"total_count": 3,
"items": [
{ "name": "react", "stargazers_count": 220000, "language": "JavaScript", "fork": false },
{ "name": "vue", "stargazers_count": 207000, "language": "TypeScript", "fork": false },
{ "name": "angular","stargazers_count": 93000, "language": "TypeScript", "fork": false }
]
}
// Get all repo names:
$.items[*].name
→ ["react", "vue", "angular"]
// Get repos with > 200,000 stars:
$.items[?(@.stargazers_count > 200000)].name
→ ["react", "vue"]
// Get TypeScript repos:
$.items[?(@.language == 'TypeScript')].name
→ ["vue", "angular"]
// Get total count:
$.total_count
→ 3
Example: Kubernetes Config Query
// Input: Kubernetes deployment config
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"spec": {
"replicas": 3,
"template": {
"spec": {
"containers": [
{
"name": "app",
"image": "myapp:1.2.0",
"resources": {
"limits": { "cpu": "500m", "memory": "128Mi" }
}
}
]
}
}
}
}
// Get replica count:
$.spec.replicas
→ 3
// Get container image:
$.spec.template.spec.containers[0].image
→ "myapp:1.2.0"
// Get CPU limit:
$.spec.template.spec.containers[0].resources.limits.cpu
→ "500m"
// Get all container names:
$.spec.template.spec.containers[*].name
→ ["app"]
// Query: $.users[?(@.role == 'admin')].name
// JavaScript (jsonpath library):
const jsonpath = require('jsonpath');
const result = jsonpath.query(data, '$.users[?(@.role == "admin")].name');
// Python (jsonpath-ng):
from jsonpath_ng import parse
expr = parse('$.users[?(@.role == "admin")].name')
result = [match.value for match in expr.find(data)]
// Java (Jayway JsonPath):
List<String> names = JsonPath.read(json, "$.users[?(@.role == 'admin')].name");
// jq equivalent:
jq '[.users[] | select(.role == "admin") | .name]' data.json
Paste your JSON in the left panel and write a JSONPath expression to extract exactly the data you need. Results are highlighted in the JSON and listed in the output panel.
Example: Basic Field Selection
// Input JSON:
{
"store": {
"name": "Tech Store",
"location": "New York",
"inventory": {
"total": 500,
"categories": 12
}
}
}
// Queries:
$.store.name → "Tech Store"
$.store.location → "New York"
$.store.inventory.total → 500
$.store → { "name": "Tech Store", ... }
$ → entire document