DevFormatter

jq Playground

Filter:
JSON Input
1
Result
Run a filter to see results here.

jq Playground — Online jq Editor

How it works

Last updated: November 2026

jq is a lightweight, command-line JSON processor that lets you slice, filter, map, and transform JSON data using a concise expression language. This playground runs the real jq 1.6 engine compiled to WebAssembly — no install required, and your data never leaves your browser.

Paste JSON into the left panel, type a jq filter in the toolbar, and click Run. The result appears on the right, colour-coded as a JSON value or a plain string. Use the sample menu to explore common patterns.

jq Quick Reference

Filter What it does Example
.foo Access object field .name → "Alice"
.foo.bar Nested field access .user.email
.[] Iterate array / object values .items[]
.[n] Array element by index .[0], .[-1]
.[m:n] Array slice .[0:3]
[ expr ] Collect results into array [.users[].name]
{ k: expr } Build new object {id, name: .fullName}
select(expr) Filter by condition select(.active)
map(expr) Transform every array element map(.price * 1.2)
sort_by(f) Sort array by field sort_by(.age)
group_by(f) Group into sub-arrays group_by(.status)
length Count items / string length .items | length
add Sum / concatenate array [.prices[]] | add
keys, values Object keys / values as arrays . | keys
has("k") Test key existence select(has("email"))
a // b Alternative (default if null) .name // "Unknown"
type Return type as string . | type → "array"
tostring, tonumber Type conversion .id | tostring
not Boolean negation select(.active | not)
a | b Pipe output of a into b .users[] | .name

Understanding jq's Output Model

The single most common jq beginner mistake is confusing a stream with an array. Understanding the difference unlocks the rest of jq's behaviour.

Iterators produce streams. .users[] does not return an array — it emits one JSON value per element, one after another. When you run .users[].name from the command line, jq prints each name on its own line. Those are separate outputs, not an array.

Use [...] to collect a stream into an array. Wrapping any expression in square brackets is array construction syntax: [.users[].name] collects every streamed name into a single JSON array. This is the fix for "I expected an array but got multiple lines."

Pipes pass one value at a time. .users[] | .name applies .name to each streamed object in turn — identical to .users[].name. The pipe | does not collect; it only transforms. Chain select() into the pipeline to filter before collecting: [.users[] | select(.active) | .name].

map() is shorthand for collect-then-transform. map(expr) is exactly [.[] | expr] — it iterates, applies, and collects back into an array automatically. Use it when input and output are both arrays.

Tips & Tricks

Collect with [ ]

Without brackets, .users[].name streams one value per line. Wrap in [...] to get a single JSON array back.

Short object construction

{id, name} is shorthand for {id: .id, name: .name} — handy for picking a subset of fields.

Chain select + map

map(select(.active)) is equivalent to [.[] | select(.active)] — pick whichever reads better to you.

Safe field access with ?

Append ? to suppress errors on missing keys or wrong types: .foo? returns null instead of an error if foo is absent.

Debug mid-pipeline

Insert | debug | anywhere in a pipeline to print the current value to stderr without breaking the chain.

Flatten nested arrays

flatten collapses all nested arrays into one. flatten(1) flattens only one level deep, preserving deeper nesting.

Code Examples

Node.js (jq-web)

const jq = await import('jq-web');
const data = { users: [{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }] };
const names = jq.json(data, '[.users[].name]');
console.log(names); // ["Alice", "Bob"]

Command line (jq CLI)

# Install jq (macOS)
brew install jq

# Filter from file
jq '.users[].name' data.json

# Filter from stdin
curl -s api.example.com/users | jq '.[0].email'

# Select and transform
jq '[.items[] | select(.active) | {id, name}]' data.json

Python (subprocess)

import subprocess, json

data = json.dumps({"users": [{"name": "Alice"}, {"name": "Bob"}]})
result = subprocess.run(
    ["jq", "[.users[].name]"],
    input=data, capture_output=True, text=True
)
print(result.stdout)  # ["Alice","Bob"]

Frequently Asked Questions

What is jq?
jq is a lightweight, portable command-line JSON processor written in C, first released in 2012. It has no runtime dependencies and is available via brew install jq (macOS), apt-get install jq (Debian/Ubuntu), and winget install jqlang.jq (Windows). jq's expression language is inspired by functional languages — every filter takes JSON input and produces JSON output, and filters are composed with the pipe | operator. This playground runs jq-web 0.6, compiled from the jq 1.6 source via WebAssembly. See the official jq manual for the full filter reference.
What is jq used for?
jq is used to query and transform JSON from the command line or in scripts. Common uses: extracting specific fields from API responses (curl -s api.example.com/users | jq '.[].name'), filtering arrays by condition ([.[] | select(.active)]), reshaping objects into a new structure ({id: .user_id, label: .display_name}), pretty-printing compact JSON, and transforming CI/CD pipeline JSON output in shell scripts. For XPath-style JSON queries, the JSONPath Playground is an alternative.
What does . mean in jq?
A single dot (.) is the identity filter — it outputs the input unchanged. It is also used to access object fields: .name returns the value of the name key, and .user.email chains field access to reach nested values.
How do I filter an array with jq?
Use .[] to iterate over array elements, then pipe to select() to filter: .items[] | select(.active == true). Wrap in brackets to collect results back into an array: [.items[] | select(.active == true)].
How do I extract a field from every object in an array?
Use the iterator and field access together: [.users[].name] collects the name field from every object in the users array into a new array. Without the brackets, .users[].name streams each value as a separate output line.
What is the difference between .[] and .[n] in jq?
.[] iterates over all elements of an array or all values of an object. .[n] accesses a single element by index — .[0] returns the first element, .[-1] returns the last.
How do I reshape JSON with jq?
Use object construction syntax: {id: .id, fullName: (.first_name + " " + .last_name)} builds a new object. Combined with the array iterator, [.users[] | {id, name}] maps an array to a new structure.
Is my data sent to a server?
No. All jq processing runs entirely in your browser using a WebAssembly build of jq. Your JSON data never leaves your machine and no account or installation is required.
What version of jq does this playground support?
The playground uses jq-web 0.6, compiled from jq 1.6 source via Emscripten/WebAssembly. It supports the full jq 1.6 filter language including select, map, reduce, path, and all built-in functions.
How do I handle null values in jq?
Use the alternative operator // to provide a default: .name // "Unknown" returns "Unknown" if name is null or absent. select(. != null) removes null values from a stream.
How do I count items in jq?
Use the length built-in: .items | length returns the number of elements. For filtered counts: [.items[] | select(.active)] | length.
How do I sort and group with jq?
sort_by(.field) sorts an array by a field. group_by(.category) groups elements into sub-arrays by a shared field. Add | reverse after sort_by for descending order.
Why does .users[].name give multiple lines instead of an array?
.users[].name is a streaming expression — the iterator .[] emits one value per element, so jq prints each name on its own line as a separate output. To collect all values into a single JSON array, wrap the expression in brackets: [.users[].name]. The brackets are array construction syntax in jq, not grouping syntax. This is the most common jq beginner confusion.
What is the jq pipe operator and how does it work?
The pipe | passes the output of the left-hand expression as input to the right-hand expression — identical in concept to Unix shell pipes, but passing structured JSON values rather than text. In .users[] | .name, the iterator streams each user object and .name is applied to each in turn. Pipes chain transformations: .users[] | select(.active) | .name iterates, then filters, then extracts — in that order.
What is the difference between map() and .[] | in jq?
map(expr) is shorthand for [.[] | expr] — it applies an expression to every element and collects results back into an array automatically. Use map() when input is an array and you want an array back: map(.price * 1.1). Use .[] | expr when you need to pipe results into further operations or filter before collecting: [.[] | select(.active) | .name]. map(select(.active)) and [.[] | select(.active)] are equivalent.
How do I merge two JSON objects with jq?
Use the + operator: .defaults + .overrides merges the two objects, with the right-hand value winning on duplicate keys. The * operator performs a recursive (deep) merge: {"a": {"x": 1}} * {"a": {"y": 2}} produces {"a": {"x": 1, "y": 2}} rather than replacing the nested object entirely. Use + for shallow merges and * for deep merges.
How do I use jq with curl to process API responses?
Pipe curl output directly to jq: curl -s https://api.github.com/repos/jqlang/jq/releases | jq '.[0].tag_name' returns the latest release tag. The -s flag silences curl's progress output. For APIs requiring headers: curl -s -H "Authorization: Bearer $TOKEN" https://api.example.com/users | jq '[.[] | {id, name}]'. Add --fail to curl so it exits non-zero on HTTP errors before the response reaches jq.

Related Tools

Other free developer tools available on DevFormatter.