JSONPath Examples — Select and Filter JSON Data

💡JSONPath is a query language for JSON similar to XPath for XML. Use $ to start from root, dot notation for properties, bracket notation for arrays. Filter expressions with [?(@.property==value)] select items matching a condition. Use the JSON Formatter to explore and navigate JSON structures.

Examples

Root object access

❌ Wrong

data['store']['book'][0]['title']

✅ Fixed

$.store.book[0].title

$ is root. Dot notation and bracket notation are equivalent in JSONPath.

All items in array

❌ Wrong

$.store.book[0] // only first item

✅ Fixed

$.store.book[*] // all items
// or
$.store.book // returns the array

[*] wildcard selects all items. Without index, JSONPath returns the whole array.

Filter by property value

❌ Wrong

$.books // returns all books

✅ Fixed

$.books[?(@.price < 10)] // books under $10
$.books[?(@.author=='Tolkien')] // by author

Filter expressions use @. to reference the current object being evaluated.

Recursive search

❌ Wrong

$.level1.level2.level3.name

✅ Fixed

$..name // finds 'name' at any depth

.. operator searches recursively. Useful when you don't know the nesting level.

Explore Your JSON

Real-World Usage

Extract nested API response field

const data = { users: [{ id: 1, name: 'John', address: { city: 'NYC' } }] };
// JSONPath: $.users[0].address.city
// Result: 'NYC'

Dot notation traverses nested objects. [0] selects the first array item.

Filter array by condition

// JSONPath: $.orders[?(@.status=='shipped')]
// Selects all orders where status is 'shipped'
const shipped = jsonpath.query(data, '$.orders[?(@.status=="shipped")]');

@.status refers to the current array item's status property.

Get all values for a key

// JSONPath: $..price
// Gets ALL price values at any depth
const prices = jsonpath.query(data, '$..price');

.. is recursive descent — searches at all levels of nesting.

Related Guides

Frequently Asked Questions

What is the difference between JSONPath and jq?

JSONPath is a query language — it selects values. jq is a full command-line processor that can also transform, filter, and reshape JSON. JSONPath is simpler; jq is more powerful.

Does JSONPath work in JavaScript natively?

No native support — use a library like jsonpath or jsonpath-plus. In browsers, lodash's _.get() handles simple nested access, and JSON Pointer (RFC 6901) is supported in some APIs.

What does .. mean in JSONPath?

.. is recursive descent — it searches at all levels of nesting. $..price finds all price values anywhere in the JSON structure, regardless of how deeply nested.

All tools run in your browser. Your data never leaves your device.