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

jq Playground

Run real jq filters on your JSON, compiled to WebAssembly. Runs in your browser.

Try jq filters on your JSON and see the output as you type. This is the real jq, compiled to WebAssembly, running in your browser. For inputs over 20 MB, use the JSONPath Tester or the JMESPath Playground.

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 filter, or type: suggestions come from the data.
  3. Read the output as JSON, a table or text. Explain shows each stage of the pipeline, and a hint offers a fix when a filter fails or finds nothing.
  4. Copy for… gives the filter as a jq command, or Python or JavaScript code.

Read more: Compare two JSON files: values, key order and saved history · How to view and query API responses and NDJSON logs · 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. JSONPath and JMESPath work on files of hundreds of megabytes; jq on inputs up to about 20 MB. 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.

Filter records and return only the IDs

Use the three-order input shown below:

{"orders":[{"id":"ord_001","status":"paid","total":89},{"id":"ord_002","status":"pending","total":149},{"id":"ord_003","status":"pending","total":29}]}

Run:

[.orders[] | select(.status == "pending" and .total > 100) | .id]

The result is ["ord_002"]. The brackets collect the emitted IDs into an array. .orders | length returns 3; [.orders[].total] | add returns 267.

jq loads when this page needs it. Keep jq input under its 20 MB limit. For larger files, try the JSONPath tester or JMESPath playground. Our query comparison runs the same tasks in all three languages.

GigaJSON jq playground filtering three orders to return ord_002GigaJSON jq playground filtering three orders to return ord_002 (dark theme)
This jq filter selects pending orders over 100 and returns their IDs. Screenshots follow the page theme. Click to view full size.

jq syntax, with examples

Each example runs on the bookstore data in the playground with jq 1.8, the jq this page runs, and shows its real output. When a filter gives several outputs, each is on its own line, as jq prints them. Try it loads the example above.

. The whole input

jq
.store.name
Result
"Corner Books"

.a.b A field inside a field

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

.[0] .[-1] One item by position. -1 is the last

jq
.store.books[-1].title
Result
"The Lord of the Rings"

.[1:3] A slice of a list

jq
.store.books[1:3] | map(.title)
Result
[
  "Sword of Honour",
  "Moby Dick"
]

.[] Every item, one output each

jq
.store.books[].title
Result
"Sayings of the Century"
"Sword of Honour"
"Moby Dick"
"The Lord of the Rings"

| Pass each output to the next filter

jq
.store.books[] | .author
Result
"Nigel Rees"
"Evelyn Waugh"
"Herman Melville"
"J. R. R. Tolkien"

select( ) Keep the values where the condition is true

jq
.store.books[] | select(.price < 10) | .title
Result
"Sayings of the Century"
"Moby Dick"

and or not Combine conditions

jq
.store.books[] | select(.price < 10 and (.tags | index("fiction"))) | .title
Result
"Moby Dick"

{ } Build an object. {title} is short for {title: .title}

jq
.store.books[] | {title, price}
Result
{"title":"Sayings of the Century","price":8.95}
{"title":"Sword of Honour","price":12.99}
{"title":"Moby Dick","price":8.99}
{"title":"The Lord of the Rings","price":22.99}

[ ] Collect every output into one list

jq
[.store.books[].price]
Result
[
  8.95,
  12.99,
  8.99,
  22.99
]

// A default when the value is null or missing

jq
.store.books[0] | .isbn // "none"
Result
"none"

"\( )" Put values into text

jq
.store.books[0] | "\(.title) costs \(.price)"
Result
"Sayings of the Century costs 8.95"

as $name Keep a value for later

jq
.store.name as $shop | .store.books[0] | "\(.title) at \($shop)"
Result
"Sayings of the Century at Corner Books"

jq functions

jq has hundreds of built-in functions. These are the ones most filters use. Functions that run on each item take it as . inside their parentheses.

length How many items, keys or characters

jq
.store.books | length
Result
4

keys The keys of an object, sorted

jq
.store.books[0] | keys
Result
[
  "author",
  "price",
  "tags",
  "title"
]

map( ) Apply a filter to each item of a list

jq
.store.books | map(.title)
Result
[
  "Sayings of the Century",
  "Sword of Honour",
  "Moby Dick",
  "The Lord of the Rings"
]

sort_by( ) Sort a list by a value

jq
.store.books | sort_by(.price) | map(.title)
Result
[
  "Sayings of the Century",
  "Moby Dick",
  "Sword of Honour",
  "The Lord of the Rings"
]

group_by( ) Group the items that share a value

jq
.store.books | group_by(.tags[0]) | map({tag: .[0].tags[0], count: length})
Result
[{"tag":"fantasy","count":1},{"tag":"fiction","count":2},{"tag":"quotes","count":1}]

unique Sort and drop duplicates

jq
[.store.books[].tags[]] | unique
Result
[
  "classic",
  "fantasy",
  "fiction",
  "quotes",
  "war"
]

add Add up numbers, or join lists and strings

jq
.store.books | map(.price) | add
Result
53.92

max_by( ) min_by( ) The item with the largest or smallest value

jq
.store.books | max_by(.price) | .title
Result
"The Lord of the Rings"

test( ) A string matches a regular expression

jq
.store.books[] | select(.title | test("^S")) | .title
Result
"Sayings of the Century"
"Sword of Honour"

split( ) join( ) Split text into a list, or join a list into text

jq
[.store.books[].author] | join(", ")
Result
"Nigel Rees, Evelyn Waugh, Herman Melville, J. R. R. Tolkien"

to_entries An object as a list of {key, value}

jq
.store.books[0] | to_entries | map(.key)
Result
[
  "title",
  "author",
  "price",
  "tags"
]

has( ) An object has a key

jq
.store.books[] | has("isbn")
Result
false
false
false
false

jq command-line recipes

Each recipe is a full jq command for bash or zsh, with its output on the example data in data.json. -r prints strings without quotes, and -c prints each output on one line.

Pretty-print a file

bash
jq '.store.books[0]' data.json
Result
{
  "title": "Sayings of the Century",
  "author": "Nigel Rees",
  "price": 8.95,
  "tags": [
    "quotes"
  ]
}

jq . data.json prints the whole file indented and coloured.

Pick a few fields from each record

bash
jq -c '.store.books[] | {title, price}' data.json
Output
{"title":"Sayings of the Century","price":8.95}
{"title":"Sword of Honour","price":12.99}
{"title":"Moby Dick","price":8.99}
{"title":"The Lord of the Rings","price":22.99}

Filter records by a value

bash
jq '[.store.books[] | select(.price < 10) | .title]' data.json
Result
[
  "Sayings of the Century",
  "Moby Dick"
]

Count the items

bash
jq '.store.books | length' data.json
Result
4

Add up a field

bash
jq '.store.books | map(.price) | add' data.json
Result
53.92

Sort by a field

bash
jq '.store.books | sort_by(.price) | map(.title)' data.json
Result
[
  "Sayings of the Century",
  "Moby Dick",
  "Sword of Honour",
  "The Lord of the Rings"
]

Group and count

bash
jq '.store.books | group_by(.tags[0]) | map({tag: .[0].tags[0], count: length})' data.json
Result
[{"tag":"fantasy","count":1},{"tag":"fiction","count":2},{"tag":"quotes","count":1}]

CSV for a spreadsheet

bash
jq -r '.store.books[] | [.title, .price] | @csv' data.json
Output
"Sayings of the Century",8.95
"Sword of Honour",12.99
"Moby Dick",8.99
"The Lord of the Rings",22.99

@csv quotes each field as CSV needs; -r prints the lines as they are. Redirect to a file with > books.csv.

A line of text per record

bash
jq -r '.store.books[] | "\(.title): \(.price)"' data.json
Output
Sayings of the Century: 8.95
Sword of Honour: 12.99
Moby Dick: 8.99
The Lord of the Rings: 22.99

Every distinct tag

bash
jq '[.store.books[].tags[]] | unique' data.json
Result
[
  "classic",
  "fantasy",
  "fiction",
  "quotes",
  "war"
]

IDs of running EC2 instances, one per line

bash
jq -r '.Reservations[].Instances[] | select(.State.Name == "running") | .InstanceId' data.json
Output
i-0f3a9c2e7b1d45e01
i-0b5e2f7a9c3d18e03

Pipe aws ec2 describe-instances into it, or use the AWS CLI's own --query (see the JMESPath Playground).

Common jq errors and how to fix them

The messages come from jq 1.8, the jq this page runs; the jq command prints the same ones. The playground spots many of these mistakes as you type and offers the fix.

jq: error: Cannot index array with string ("price")

books is a list, and a list has no price field. [] takes each item in turn, so .price is read from each book.

jq
Wrong:
.store.books | select(.price < 10) | .title
Right:
.store.books[] | select(.price < 10) | .title
This playground
jq: error (at /dev/stdin:0): Cannot index array with string ("price")

jq: error: syntax error, unexpected INVALID_CHARACTER

jq strings use double quotes. A single quote is not a character jq reads; in a shell, the whole filter goes in single quotes instead.

jq
Wrong:
.store.books[] | select(.author == 'Herman Melville') | .title
Right:
.store.books[] | select(.author == "Herman Melville") | .title
This playground
jq: error: syntax error, unexpected INVALID_CHARACTER

jq: error: store/0 is not defined

Paths start with a dot. Without it, jq looks for a function called store.

jq
Wrong:
store.books
Right:
.store.books
This playground
jq: error: store/0 is not defined

jq: error: lenght/0 is not defined

A misspelt function looks like an unknown one to jq. The /0 is the number of arguments it was called with.

jq
Wrong:
.store.books | lenght
Right:
.store.books | length
This playground
jq: error: lenght/0 is not defined

jq: error: syntax error, unexpected end of file

A parenthesis is never closed, so jq reaches the end of the filter while still expecting ).

jq
Wrong:
.store.books[] | select(.price < 10 | .title
Right:
.store.books[] | select(.price < 10) | .title
This playground
jq: error: syntax error, unexpected end of file, expecting ';' or ')'

jq: error: Cannot iterate over null (null)

Field names are case-sensitive. .store.Books is null, and [] can't take the items of null.

jq
Wrong:
.store.Books[].title
Right:
.store.books[].title
This playground
jq: error (at /dev/stdin:0): Cannot iterate over null (null)

Every item comes back from select( = )

A single = in jq sets a value: it changes each item's price to 8.99, which counts as true, so select keeps everything. Compare with ==.

jq
Wrong:
[.store.books[] | select(.price = 8.99)]
Right:
[.store.books[] | select(.price == 8.99)]
This playground
No error. The result is [{"title":"Sayings of the Century","author":"Nigel Rees","price":8.95,"tags":["quotes"]},…

Quoting a filter on Windows

In bash and zsh, put the filter in single quotes so the shell leaves it alone. In the Windows command prompt, single quotes don't work; the simplest fix is to save the filter in a file and run jq -f filter.jq data.json.

Questions

Is this the real jq?

Yes. It's jq compiled to WebAssembly (jq-wasm), so filters behave the way they do on the command line.

How large can the input be?

Up to about 20 MB for jq in the browser. For bigger documents, use JSONPath or JMESPath; they work on hundreds of megabytes.

Which jq version is it?

jq 1.8.2, through jq-wasm 3.0.0.

How do I select objects by a field value?

Use select: .orders[] | select(.total > 100) | .id returns the ID of each order over 100. Wrap the whole filter in [ ] to get one list instead of separate results.

How do I print strings without quotes?

Run jq with -r (raw output): jq -r '.orders[].id' data.json prints each ID on its own line, without quotes.

How do I turn JSON into CSV with jq?

Build a list per record and pass it to @csv, with -r: jq -r '.orders[] | [.id, .total] | @csv' data.json. @csv quotes each field as CSV needs.

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