jq Playground
Filter:Run a filter to see results here.
How it works
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 |
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, command-line JSON processor. It lets you slice, filter, map, and transform JSON data using a simple expression language. jq is commonly used in shell scripts to process API responses, extract fields from JSON files, and reshape data before passing it to other tools.
- What is jq used for?
- jq is used to query and transform JSON from the command line or in scripts. Common uses include extracting specific fields from API responses (
curl ... | jq '.data[].id'), filtering arrays by a condition, reshaping objects into a new structure, and pretty-printing JSON for readability. - 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:.namereturns the value of the name key, and.user.emailchains field access to reach nested values. - How do I filter an array with jq?
- Use
.[]to iterate over array elements, then pipe toselect()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[].namestreams 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
lengthbuilt-in:.items | lengthreturns 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| reverseaftersort_byfor descending order.
Related Tools
Other free developer tools available on DevFormatter.
JSON Formatter
Format, validate, minify, and sort JSON. Detects duplicate keys and converts to YAML.
YAML Formatter
Format, validate, and convert YAML. Detects YAML 1.1 coercion risks and expands anchors.
XML Formatter
Format, validate, and convert XML. Checks well-formedness with exact error positions.
JSONPath Playground
Query JSON with $.store.books[*].title syntax. Used in Kubernetes, OpenAPI, and Postman.