JsonSnacksRuns in your browser

JSONPath cheat sheet

JSONPath selects values from JSON using expressions that start with $ for the root. Use .name for a child, [0] for an array index, [*] for all items, .. to search at any depth and [?(@.price > 10)] to filter items.

Try it: JSONPath PlaygroundWrite a JSONPath and see the matches highlighted live.

Syntax at a glance

  • $ is the root of the document.
  • .key or ['key'] selects a child. Use brackets when a key has spaces or symbols.
  • [0] selects the first item and [-1] selects the last.
  • [*] or .* selects every child.
  • .. searches at any depth: $..price finds every price.
  • [0,2] selects several items. [1:3] is a slice from index 1 up to, not including, 3.
  • [?(@.price > 10)] keeps items where the condition is true. @ is the current item.

Examples

Using a bookshop document with store.books[]:

$.store.books[*].title              all titles
$.store.books[0]                    the first book
$.store.books[-1:]                  the last book
$..price                            every price at any depth
$.store.books[?(@.price > 40)]      books over 40
$.store.books[?(@.tags)]            books that have tags
$.store.books[?(@.title =~ /^A/)]   titles starting with A

Filters

Combine conditions with && and ||, and negate with !. Compare with ==, !=, <, <=, > and >=. Strings need quotes: @.status == 'shipped'.

Implementations differ

JSONPath was described informally before RFC 9535 standardised it, so libraries differ on details such as filter syntax and how missing values compare. Test your expression in the same library you will run it in when exact behaviour matters.

Frequently asked questions

What is the difference between JSONPath and JMESPath?

Both query JSON. JSONPath looks like XPath and uses $ and @. JMESPath uses a different syntax with pipes and functions. They are not interchangeable.

How do I get the last item of an array?

Use a negative index: $.items[-1:] or $.items[-1] in implementations that support it.

Published 2026-10-23. Last updated 23 October 2026.