Skip to the tool
GigaJSON JSONPath Tester
All tools
Format and check
View and query
Convert
JSON to code
Encode and decode
Sample files
Guides Open GigaJSON

JSONPath Tester

Test JSONPath expressions on your JSON and see the matches as you type. Runs in your browser.

Write a JSONPath expression and see what it selects in your JSON as you type. JMESPath and jq are one click away, on the same data. To get the path of a value by clicking it, use the JSON Path Finder.

How to use it

  1. Start from the bookstore example, or paste your own JSON with Edit or Open file.
  2. Pick an "I want to" pattern, click a line of the data to put its path in the query, or type: suggestions come from the data.
  3. Read the matches as JSON, a table or text. Explain shows each step, and a hint offers a fix when a query fails or finds nothing.
  4. Copy for… gives the query as JavaScript or Python code.

Read more: JSONPath examples in JavaScript, Python, PostgreSQL and kubectl · jq vs JSONPath vs JMESPath: the same 8 tasks in all three

Private, and made for big files

This tool runs in your browser, in a background worker: nothing you paste or open is uploaded, and nothing is kept after you leave. JSON and XML input can be up to 1 GB, depending on available memory. Processing runs in a background worker; large analyses can take a minute or more. Already loaded features keep working if your connection drops. Loading another tool or jq for the first time needs a connection. When one tool isn't enough, GigaJSON opens your data with a tree, a table, JSONPath/JMESPath/jq queries, transforms, diff and history.

Six JSONPath expressions on one document

Load this document of three orders:

{"orders":[{"id":"ord_001","status":"paid","total":89,"customer":{"name":"Ada","country":"IN"},"items":[{"sku":"KB-01","qty":1}]},{"id":"ord_002","status":"pending","total":149,"customer":{"name":"Sam","country":"NO"},"items":[{"sku":"MS-02","qty":2},{"sku":"KB-01","qty":1}]},{"id":"ord_003","status":"pending","total":29,"customer":{"name":"Lea","country":"DE"},"items":[{"sku":"CB-03","qty":3}]}]}
ExpressionResult
$.orders[*].id["ord_001","ord_002","ord_003"]
$.orders[?(@.total > 100)].id["ord_002"]
$.orders[?(@.status == 'pending')].customer.name["Sam","Lea"]
$..sku["KB-01","MS-02","KB-01","CB-03"]
$.orders[-1:].id["ord_003"]
$.orders[0].customer[{"name":"Ada","country":"IN"}]

[*] takes every item, [?( )] keeps the items where the condition is true (@ is the current item), .. searches every level, and [-1:] is a slice holding the last item. JSONPath always returns a list of matches, even for a single value.

JSONPath only selects. To count, sum or build new objects, switch the tab to JMESPath or jq: for example, sum(orders[].total) in JMESPath gives 267. The query-language guide solves eight tasks in all three, and the JSON Path Finder writes the path to any value you click.

JSONPath syntax, with examples

Each example runs on the bookstore data in the playground with jsonpath-plus, the JSONPath library this page runs, and shows its real result. A path with several matches gives a list; one match is shown on its own. Try it loads the example above.

$ The whole document, where every path starts

JSONPath
$.store.name
Result
"Corner Books"

.name ['name'] A field. Brackets work for any name, even with spaces or dots

JSONPath
$.store['name']
Result
"Corner Books"

[0] One item by position, from 0

JSONPath
$.store.books[0].title
Result
"Sayings of the Century"

[-1:] The last item (a slice from the end)

JSONPath
$.store.books[-1:].title
Result
"The Lord of the Rings"

[start:end] A slice of a list: start included, end not

JSONPath
$.store.books[0:2].title
Result
[
  "Sayings of the Century",
  "Sword of Honour"
]

[0,2] Several items by position

JSONPath
$.store.books[0,2].title
Result
[
  "Sayings of the Century",
  "Moby Dick"
]

[*] .* Every item of a list, or every value of an object

JSONPath
$.store.books[*].author
Result
[
  "Nigel Rees",
  "Evelyn Waugh",
  "Herman Melville",
  "J. R. R. Tolkien"
]

.. Search every level for a field

JSONPath
$..price
Result
[
  8.95,
  12.99,
  8.99,
  22.99
]

[?( )] Keep the items where the condition is true. @ is the item being tested

JSONPath
$.store.books[?(@.price < 10)].title
Result
[
  "Sayings of the Century",
  "Moby Dick"
]

['a','b'] Several fields of each item

JSONPath
$.store.books[*]['title','price']
Result
["Sayings of the Century",8.95,"Sword of Honour",12.99,"Moby Dick",8.99,"The Lord of the Rings",22.99]

What a JSONPath filter can test

In jsonpath-plus, the condition in [?( )] is a small JavaScript expression about @, the item being tested. Other JSONPath libraries support less: check the one your code uses.

== != Equal, not equal

JSONPath
$.store.books[?(@.price == 8.99)].title
Result
"Moby Dick"

< <= > >= Compare numbers

JSONPath
$.store.books[?(@.price > 12)].title
Result
[
  "Sword of Honour",
  "The Lord of the Rings"
]

&& || ! And, or, not

JSONPath
$.store.books[?(@.price < 10 && @.tags.includes('fiction'))].title
Result
"Moby Dick"

.includes() A list contains a value, or a string contains text

JSONPath
$.store.books[?(@.tags.includes('fiction'))].title
Result
[
  "Sword of Honour",
  "Moby Dick"
]

.startsWith() A string starts with text

JSONPath
$.store.books[?(@.title.startsWith('S'))].title
Result
[
  "Sayings of the Century",
  "Sword of Honour"
]

.match(/…/) A string matches a regular expression

JSONPath
$.store.books[?(@.author.match(/Melville/))].title
Result
"Moby Dick"

.length The length of a list or a string

JSONPath
$.store.books[?(@.tags.length > 1)].title
Result
[
  "Sword of Honour",
  "Moby Dick"
]

.toLowerCase() Compare text without case

JSONPath
$.store.books[?(@.title.toLowerCase().includes('sword'))].title
Result
"Sword of Honour"

JSONPath recipes

Common tasks, each as JavaScript with jsonpath-plus (the library this page runs) and its result on the example data. In Python, jsonpath-ng's parse reads the same paths, but its filters don't run JavaScript methods such as includes.

Every author

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[*].author", json: data })
Result
[
  "Nigel Rees",
  "Evelyn Waugh",
  "Herman Melville",
  "J. R. R. Tolkien"
]

Books under 10

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[?(@.price < 10)].title", json: data })
Result
[
  "Sayings of the Century",
  "Moby Dick"
]

Books with a tag

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[?(@.tags.includes('fiction'))].title", json: data })
Result
[
  "Sword of Honour",
  "Moby Dick"
]

The last book

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[-1:].title", json: data })
Result
"The Lord of the Rings"

[-1] without the colon isn't supported everywhere; the slice [-1:] is.

Every price, at any depth

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$..price", json: data })
Result
[
  8.95,
  12.99,
  8.99,
  22.99
]

A case-insensitive search

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[?(@.title.toLowerCase().includes('sword'))].title", json: data })
Result
"Sword of Honour"

IDs of running EC2 instances

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.Reservations[*].Instances[?(@.State.Name == 'running')].InstanceId", json: data })
Result
[
  "i-0f3a9c2e7b1d45e01",
  "i-0b5e2f7a9c3d18e03"
]

An EC2 instance's Name tag

JavaScript
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.Reservations[*].Instances[*].Tags[?(@.Key == 'Name')].Value", json: data })
Result
[
  "web-1",
  "batch-worker",
  "api-1"
]

Common JSONPath errors and how to fix them

The messages come from jsonpath-plus, the JSONPath library this page runs. The playground spots many of these mistakes as you type and offers the fix.

jsonPath: Invalid left-hand side in assignment

A single = sets a value. In a filter, compare with ==.

JSONPath
Wrong:
$.store.books[?(@.price = 8.99)].title
Right:
$.store.books[?(@.price == 8.99)].title
This playground
jsonPath: Invalid left-hand side in assignment: @.price = 8.99

jsonPath: price is not defined

In a filter, @ is the item being tested. Its fields are written @.price; price alone is an unknown name.

JSONPath
Wrong:
$.store.books[?(price < 10)].title
Right:
$.store.books[?(@.price < 10)].title
This playground
jsonPath: price is not defined: price < 10

Unexpected "?" at character 0

The filter is never closed. A filter is written [?( … )], with both brackets.

JSONPath
Wrong:
$.store.books[?(@.price < 10).title
Right:
$.store.books[?(@.price < 10)].title
This playground
Unexpected "?" at character 0

An empty result from a filter without ?( )

Some guides write filters like JMESPath, [?price < 10]. JSONPath needs the parentheses and @.

JSONPath
Wrong:
$.store.books[?price < 10].title
Right:
$.store.books[?(@.price < 10)].title
This playground
No error. The result is []

An empty result from a filter on the wrong level

A filter tests the items of the list (or the values of the object) before it. Here that is store, whose values have no price; filter books instead.

JSONPath
Wrong:
$.store[?(@.price < 10)].title
Right:
$.store.books[?(@.price < 10)].title
This playground
No error. The result is []

An empty result from a field name in the wrong case

Field names are case-sensitive, and a path that matches nothing is not an error. The playground suggests the right name.

JSONPath
Wrong:
$.store.books[*].Title
Right:
$.store.books[*].title
This playground
No error. The result is []

Questions

Which JSONPath syntax is supported?

The common syntax: $.a.b, [0], [*], .., filters like [?(@.price < 10)] and slices. It uses the jsonpath-plus library.

What is the difference between JSONPath, JMESPath and jq?

JSONPath selects values by their path. JMESPath can also reshape them, with projections and functions. jq is a complete language for transforming JSON.

How do I test a JSONPath expression online?

Paste your JSON above and type the expression. The matches update as you type. The language tabs run JMESPath or jq on the same data, so you can compare.

How do I filter by a nested field?

Put the path after @ in the filter: $.orders[?(@.customer.country == 'NO')].id keeps the orders whose customer is in Norway and returns their IDs.

Why does JSONPath return a list for one value?

A JSONPath expression can match any number of values, so libraries return a list of matches: in code, $.orders[0].id gives ["ord_001"], not "ord_001". This page shows a single match on its own and several as a list.

How do I get the last item of a list?

Use a slice from the end: $.orders[-1:] matches the last item. Slices work in jsonpath-plus and most other JSONPath libraries.

Can a JSONPath filter use a regular expression?

In jsonpath-plus, yes: $.store.books[?(@.author.match(/Melville/))] keeps the books whose author matches. Other libraries support less in filters, so check the one your code uses.

Is my data uploaded?

No. The tool runs in your browser, in a background worker. Nothing you paste or open goes to a server, and nothing is kept after you leave the page.

All tools