JSONPath is a query language for JSON, similar to XPath for XML. It lets you extract specific values from complex JSON structures quickly and efficiently.
Basic JSONPath Syntax
Given this JSON:
{
"store": {
"books": [
{ "title": "JSON Guide", "price": 29.99 },
{ "title": "API Design", "price": 39.99 },
{ "title": "Web Security", "price": 19.99 }
],
"location": "New York"
}
}
Here are common JSONPath expressions:
$.store.books[0].title — First book's title$.store.books[*].price — All book prices$.store.books[?(@.price < 30)] — Books under $30$.store.books[?(@.price > 20)].title — Titles of books over $20$.store.. — Everything under storeEssential Operators
Practical Use Cases
JSONPath in JavaScript
// Using JSONPath Plus library
const jp = require('jsonpath-plus');
const result = jp.JSONPath({path: '$.store.books[?(@.price < 30)]', json: data});
Tips for Complex Queries
to find deeply nested values (and) and ||` (or)Use our JSON Formatter to format your data before writing JSONPath queries, or try the JSON Viewer for interactive exploration.