JSONPath Query Language

A complete reference for using JSONPath expressions in the JSON Formatter tool.

What is JSONPath?

JSONPath is a query language for JSON data, similar to how XPath works for XML. It lets you navigate into a JSON structure and extract specific values using a concise expression syntax.

In the JSON Formatter, type a JSONPath expression into the JSONPath input field. Matching results appear above the tree, and matched nodes are highlighted in blue.

Syntax Reference

ExpressionDescriptionExample
$The root object$
.keyChild property access$.store.name
['key']Bracket notation (for special characters in keys)$['first-name']
[n]Array index (0-based, negative supported)$.items[0]
[*]Wildcard — all items in an array or all values in an object$.items[*].name
.*Wildcard (dot notation)$.store.*
..Recursive descent — searches all levels$..name
[start:end]Array slice (start inclusive, end exclusive)$.items[0:3]
[?()]Filter expression$.items[?(@.price < 10)]
.lengthArray or object length$.items.length

Examples

Given this sample JSON:

{
  "store": {
    "books": [
      { "title": "The Great Gatsby", "author": "Fitzgerald", "price": 10.99, "year": 1925 },
      { "title": "To Kill a Mockingbird", "author": "Lee", "price": 8.99, "year": 1960 },
      { "title": "1984", "author": "Orwell", "price": 7.99, "year": 1949 },
      { "title": "Pride and Prejudice", "author": "Austen", "price": 6.99, "year": 1813 }
    ],
    "location": { "city": "New York", "country": "US" }
  }
}

Basic Property Access

QueryResult
$.store.location.city"New York"
$.store.books[0].title"The Great Gatsby"
$.store.books[-1].title"Pride and Prejudice" (last item)

Wildcards

QueryResult
$.store.books[*].title["The Great Gatsby", "To Kill a Mockingbird", "1984", "Pride and Prejudice"]
$.store.*All direct children of store (the books array and location object)

Recursive Descent

The .. operator searches through all nested levels:

QueryResult
$..author["Fitzgerald", "Lee", "Orwell", "Austen"]
$..price[10.99, 8.99, 7.99, 6.99]

Array Slicing

Slice syntax is [start:end] where start is inclusive and end is exclusive. Negative indices count from the end.

QueryResult
$.store.books[0:2]First two books (index 0 and 1)
$.store.books[-2:]Last two books
$.store.books[::2]Every other book (step of 2)

Filter Expressions

Filter expressions use [?()] syntax with @ referring to the current element. You can use comparison operators (==, !=, <, >, <=, >=) and logical operators (&&, ||).

QueryResult
$.store.books[?(@.price < 9)]Books cheaper than $9 (Lee, Orwell, Austen)
$.store.books[?(@.year > 1900)]Books published after 1900 (Gatsby, Mockingbird, 1984)
$.store.books[?(@.price < 9 && @.year > 1900)]Cheap books from 20th century onward (Lee, Orwell)

Length

QueryResult
$.store.books.length4

Combining Expressions

You can chain expressions to drill down into filtered results:

QueryResult
$.store.books[?(@.price < 9)].title["To Kill a Mockingbird", "1984", "Pride and Prejudice"]
$.store.books[0:2].author["Fitzgerald", "Lee"]

Tips

Ready to try it out?

Open JSON Formatter

Cloud Sync

Connected to Google Drive