JSONPath Guide

JSONPath is a query language for JSON, similar to XPath for XML. It lets you extract specific values from deeply nested JSON structures using path expressions. Used heavily in APIs, testing frameworks, and configuration tools.

Supported in: Jayway, Goessner, JSONPath Plus
Used in: AWS, Kubernetes, Postman, JMeter

Sample JSON used in examples below

{
  "store": {
    "books": [
      { "title": "Clean Code",        "author": "Robert Martin", "price": 34.99, "category": "tech" },
      { "title": "The Pragmatic Programmer", "author": "Hunt & Thomas", "price": 49.99, "category": "tech" },
      { "title": "Sapiens",           "author": "Yuval Harari",  "price": 18.99, "category": "history" },
      { "title": "Atomic Habits",     "author": "James Clear",   "price": 16.99, "category": "self-help" }
    ],
    "location": "New York"
  }
}

Operators & Syntax

OperatorDescription
$Root node — every expression starts here
.keyChild key selector
..keyRecursive descent — searches all levels
[*]Wildcard — selects all elements of an array or object
[n]Array index. Negative index counts from end.
[a:b]Array slice from index a to b (exclusive)
[a,b]Multiple indices — union selector
?(expr)Filter expression — select items where expr is true
@Current node (used inside filter expressions)

Expression Examples

ExpressionWhat it doesResult
$Root elementThe entire document
$.storeChild elementThe store object
$.store.booksNested childArray of all books
$.store.books[0]Array indexFirst book object
$.store.books[-1]Last itemLast book object
$.store.books[*]Wildcard — all itemsAll book objects
$.store.books[*].titleAll titles["Clean Code", "The Pragmatic Programmer", ...]
$.store.books[0,2]Multiple indicesFirst and third books
$.store.books[0:2]Slice (0 to 2)First two books
$..titleRecursive descent — all titles anywhereAll title values in the document
$..priceAll price valuesAll price numbers
$.store.books[?(@.price < 20)]Filter: price under 20Sapiens and Atomic Habits
$.store.books[?(@.category == "tech")]Filter: by categoryClean Code and Pragmatic Programmer
$.store.books[?(@.author =~ /James/)]Filter: regex matchAtomic Habits
$.store.books.lengthArray length4

Filter Expression Operators

Filter expressions use ?(@.field operator value) syntax. @ refers to the current item.

==Equal to
?(@.price == 34.99)
!=Not equal to
?(@.category != "tech")
<Less than
?(@.price < 20)
<=Less than or equal
?(@.price <= 34.99)
>Greater than
?(@.price > 30)
>=Greater than or equal
?(@.price >= 49.99)
=~Regex match
?(@.title =~ /Code/)
inValue in array
?(@.category in ["tech","sci"])
!inValue not in array
?(@.category !in ["tech"])