DevLab
JSON

JSONPath Syntax: Query JSON Like XPath

Learn JSONPath syntax to query, filter, and extract data from nested JSON structures.

What is JSONPath?

JSONPath is a query language for JSON, analogous to XPath for XML. It lets you navigate and extract data from JSON structures using a concise syntax.

JSONPath is widely used in tools like AWS Step Functions, Kubernetes configurations, API testing tools, and data transformation pipelines.

Basic Syntax

  • $ — Root element
  • .key or ['key'] — Access a child key
  • [n] — Access array element at index n
  • [*] — Wildcard: all elements of array or object
  • .. — Recursive descent: search all descendants
  • [start:end] — Array slice
  • [?(@.condition)] — Filter expression

Examples

Given: {"store":{"books":[{"title":"Deep Work","price":15},{"title":"Atomic Habits","price":18}]}}

  • $.store.books[0].title → "Deep Work"
  • $.store.books[*].title → ["Deep Work", "Atomic Habits"]
  • $.store.books[?(@.price > 16)].title → ["Atomic Habits"]
  • $..price → [15, 18] (recursive)

Filter Expressions

Filter expressions use [?(@.field operator value)] syntax. The @ refers to the current element being evaluated.

  • [?(@.active == true)] — Where active is true
  • [?(@.price >= 10)] — Where price >= 10
  • [?(@.name =~ /pattern/)] — Where name matches a regex (implementation-specific)

Practice with these tools

More Learning Topics