jsondecode.com logo

HomeChevronBlogChevronJSONPath Guide: Query JSON Data Like SQL (with Examples)

Blog post

JSONPath Guide: Query JSON Data Like SQL (with Examples)

Learn JSONPath syntax to query JSON data — basic expressions, wildcards, filters, recursive descent, and array slices. Includes JavaScript and Python examples.

author

Shashank Jain

Author

22/05/20260 minutes 29 seconds read
JSONPath Guide: Query JSON Data Like SQL (with Examples)JSONPath Guide: Query JSON Data Like SQL (with Examples)

Article

What is JSONPath?

JSONPath is a query language for JSON, similar to XPath for XML. It lets you extract specific values from complex JSON structures using path expressions.

Basic Syntax

ExpressionMeaning
$.store.book[0].titleFirst book title
$.store.book[*].authorAll book authors
$..authorAll authors anywhere (recursive)
$.store.book[?(@.price < 10)]Books cheaper than 10
$.store.book[-1]Last book
$.store.book[0:2]First two books (slice)

Filter Expressions

// All users with age over 18
$.users[?(@.age > 18)]

// Products in stock
$.products[?(@.inStock == true)]

// Items matching a string
$.items[?(@.status == 'active')]

JavaScript: jsonpath-plus

import { JSONPath } from 'jsonpath-plus';

const result = JSONPath({
  path: '$.store.book[?(@.price < 10)].title',
  json: data
});
console.log(result); // array of matching values

Python: jsonpath-ng

from jsonpath_ng import parse

expr = parse('$.store.book[*].author')
matches = [m.value for m in expr.find(data)]
print(matches)

Test JSONPath expressions live against your own JSON using the JSONPath Tester at jsondecode.com.

Keep reading

Recent blogs

View all

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.