What Is JSONPath?
JSONPath is a query language for JSON, analogous to XPath for XML. It lets you extract specific values from a JSON document using a concise expression syntax. Originally proposed by Stefan Goessner in 2007, JSONPath has since become a de facto standard used by tools like Kubernetes, AWS CloudFormation, Postman, and many JSON processing libraries.
Basic Syntax
Every JSONPath expression starts with `$`, which represents the root of the document. From there, you navigate using two notations:
- Dot notation:
$.store.book.title— familiar and concise - Bracket notation:
$['store']['book']['title']— required when keys contain spaces or special characters
Both styles can be mixed in a single expression.
Wildcards
The ***** wildcard matches all children of a node. $.store.book[*].author returns the author of every book in the array. $.* returns all direct children of the root object.
Array Indexing and Slicing
Arrays are zero-indexed in JSONPath: $.items[0] returns the first item. Negative indices count from the end: $.items[-1] returns the last item (support varies by implementation).
Slice notation follows Python conventions: $.items[0:3] returns the first three items. $.items[::2] returns every other item.
Recursive Descent
The `..` operator (or **) searches all levels of the document recursively. $..author returns every author field at any depth in the document — useful when you don't know the exact nesting level or when the structure varies.
Filter Expressions
Filter expressions use `?()` to return only elements that satisfy a condition:
$.store.book[?(@.price < 10)]
The @ symbol refers to the current element. Supported operators include ==, !=, <, >, <=, >=, and in some implementations =~ for regex matching.
Multiple Selectors
Some implementations support selecting multiple specific indices or keys: $.items[0,2,4] returns the first, third, and fifth items. $['name','email'] returns both fields from an object.
Where JSONPath Is Used
Kubernetes: policy definitions and field selectors use JSONPath to reference fields in resource specs. AWS Step Functions: input/output path filtering uses JSONPath to slice and reshape state data. Postman: test scripts use JSONPath to assert values in API responses. jq: while jq has its own more powerful query language, many developers use JSONPath as a gentler entry point to JSON querying.
Testing Expressions Before You Ship
The most reliable way to develop a JSONPath expression is to test it against a real document before embedding it in code or a pipeline. The DevHexLab JSONPath Tester lets you paste a JSON document and try expressions interactively, showing all matching results immediately. This avoids the feedback loop of deploying a broken expression to a pipeline or production system.
Implementation Differences
JSONPath is not fully standardised — different libraries (jsonpath-ng in Python, jsonpath-plus in JavaScript, Jayway in Java) have slightly different feature sets. The RFC 9535 specification (published 2024) aims to standardise the language, but most existing tools predate it. Always test your expressions in the environment that will run them in production.