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
- Start from the bookstore example, or paste your own JSON with Edit or Open file.
- 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.
- 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.
- 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}]}]}| Expression | Result |
|---|---|
$.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
.store.name"Corner Books".name ['name'] A field. Brackets work for any name, even with spaces or dots
.store['name']"Corner Books"[0] One item by position, from 0
.store.books[0].title"Sayings of the Century"[-1:] The last item (a slice from the end)
.store.books[-1:].title"The Lord of the Rings"[start:end] A slice of a list: start included, end not
.store.books[0:2].title[
"Sayings of the Century",
"Sword of Honour"
][0,2] Several items by position
.store.books[0,2].title[
"Sayings of the Century",
"Moby Dick"
][*] .* Every item of a list, or every value of an object
.store.books[*].author[
"Nigel Rees",
"Evelyn Waugh",
"Herman Melville",
"J. R. R. Tolkien"
].. Search every level for a field
price[
8.95,
12.99,
8.99,
22.99
][?( )] Keep the items where the condition is true. @ is the item being tested
.store.books[?(.price 10)].title[
"Sayings of the Century",
"Moby Dick"
]['a','b'] Several fields of each item
.store.books[*]['title','price']["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
.store.books[?(.price 8.99)].title"Moby Dick"< <= > >= Compare numbers
.store.books[?(.price 12)].title[
"Sword of Honour",
"The Lord of the Rings"
]&& || ! And, or, not
.store.books[?(.price 10 .tags.includes('fiction'))].title"Moby Dick".includes() A list contains a value, or a string contains text
.store.books[?(.tags.includes('fiction'))].title[
"Sword of Honour",
"Moby Dick"
].startsWith() A string starts with text
.store.books[?(.title.startsWith('S'))].title[
"Sayings of the Century",
"Sword of Honour"
].match(/…/) A string matches a regular expression
.store.books[?(.author.match(/Melville/))].title"Moby Dick".length The length of a list or a string
.store.books[?(.tags.length 1)].title[
"Sword of Honour",
"Moby Dick"
].toLowerCase() Compare text without case
.store.books[?(.title.toLowerCase().includes('sword'))].title"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
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[*].author", json: data })[
"Nigel Rees",
"Evelyn Waugh",
"Herman Melville",
"J. R. R. Tolkien"
]Books under 10
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[?(@.price < 10)].title", json: data })[
"Sayings of the Century",
"Moby Dick"
]Books with a tag
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[?(@.tags.includes('fiction'))].title", json: data })[
"Sword of Honour",
"Moby Dick"
]The last book
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[-1:].title", json: data })"The Lord of the Rings"[-1] without the colon isn't supported everywhere; the slice [-1:] is.
Every price, at any depth
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$..price", json: data })[
8.95,
12.99,
8.99,
22.99
]A case-insensitive search
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.store.books[?(@.title.toLowerCase().includes('sword'))].title", json: data })"Sword of Honour"IDs of running EC2 instances
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.Reservations[*].Instances[?(@.State.Name == 'running')].InstanceId", json: data })[
"i-0f3a9c2e7b1d45e01",
"i-0b5e2f7a9c3d18e03"
]An EC2 instance's Name tag
import { JSONPath } from 'jsonpath-plus';
JSONPath({ path: "$.Reservations[*].Instances[*].Tags[?(@.Key == 'Name')].Value", json: data })[
"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 ==.
.store.books[?(.price = 8.99)].title.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.
.store.books[?(price 10)].title.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.
.store.books[?(.price 10).title.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 @.
.store.books[?price 10].title.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.
.store[?(.price 10)].title.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.
.store.books[*].Title.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
- JSON FormatterIndent with 2 or 4 spaces, sort keys
- JSON ValidatorLine and column of the first error
- JSON MinifierRemove whitespace, see the bytes saved
- JSON RepairFixes quotes, commas, comments, AI output
- JSON Schema GeneratorA JSON Schema from examples
- JSON Schema ValidatorCheck JSON against a schema
- JSON Token CounterCount tokens, select data, compare JSON and TOON
- JSON EditorTree and code editing, undo and history
- Large JSON ViewerTree, table and search for huge files
- JSON Lines ViewerJSONL and NDJSON logs as a table
- JSON Log ViewerCount and filter JSON Lines logs
- Large CSV ViewerCSV files too big for Excel, up to 1 GB
- JSON VisualizerThe data as a graph, PNG and SVG export
- JSON DiffChanges between two documents
- JSON Path FinderClick a value, copy its path
- JSONPath TesterJSONPath, JMESPath and jq, live
- JMESPath PlaygroundJMESPath, for AWS CLI queries too
- jq PlaygroundReal jq in your browser
- JSON to CSVNested objects become dotted columns
- JSON to ExcelAn .xlsx sheet, numbers kept as numbers
- CSV to JSONDelimiters detected, 007 stays 007
- JSON to XML@keys become attributes
- XML to JSONRSS feeds, sitemaps, SOAP responses
- JSON to YAMLReadable YAML, ambiguous strings quoted
- YAML to JSONAnchors and multiple documents
- JSON Lines to JSONNDJSON or JSONL into one array
- JSON to JSON LinesA JSON array as one record per line
- JSON to TOONConvert JSON to TOON, with token counts
- JSON to MermaidA flowchart or class diagram, drawn
- JSON SplitterCut a big file into parts, or sample it
- JSON to TypeScriptInterfaces inferred from your data
- JSON to GoGo structs with json tags
- JSON to RustRust structs that derive serde's Serialize and Deserialize
- JSON to PythonPython dataclasses with type hints
- JSON to JavaJava classes with getters and setters
- JSON to C#C# classes with System.Text.Json attributes
- JSON to KotlinKotlin data classes
- JSON to SwiftSwift structs that conform to Codable, with CodingKeys
- JSON to DartDart classes with fromJson and toJson
- JSON to ZodZod schemas with TypeScript types inferred from them
- JWT DecoderHeader, payload and expiry, locally
- JSON EscapeText to a JSON string and back
- Sample JSON FilesDownload test JSON, 100 KB to 1 GB
- Sample JSON Lines FilesDownload test NDJSON, one record per line
- Sample CSV FilesDownload test CSV, 100 KB to 1 GB
- Sample XML FilesDownload test XML, 100 KB to 1 GB
- Sample GeoJSON FilesPoints, lines and polygons, up to 1 GB
- Sample Nested JSONRecords 8 levels deep, up to 1 GB
- Sample Unicode JSON13 scripts, emoji and escapes
- Sample API ResponsesJSON:API, HAL, GraphQL, pages, errors
- Large JSON File GeneratorTest data from 100 KB to 1 GB