jq Playground
Type a jq filter and see the result instantly. Paste your JSON (or JSON Lines), toggle jq flags like -r, -c and -s, and learn from a library of ready-made filters. Everything runs locally in your browser.
Last updated:
Runs live as you type. Ctrl+Enter runs now. Multi-line filters, def functions and comments (#) are fine.
Example filter library
How to use the jq Playground
- Paste your JSON into the Input box, drop a .json file on it, or keep the sample data.
- Type a jq filter such as
.users[] | select(.active) | .name. The output updates as you type. - Toggle flags like
-rfor raw strings,-cfor one line per result or-sto slurp JSON Lines into an array. - Browse the example library and click any card to load a working filter you can adapt.
- Copy or download the output, or copy the matching
jqcommand to run in your terminal.
jq cheat sheet
| Filter | What it does | Example result |
|---|---|---|
. | Identity: the whole input | Pretty-printed JSON |
.key, .a.b, ."my-key" | Object field (null if missing) | .name → "Ada" |
.[0], .[-1], .[2:4] | Array index, from the end, slice | [1,2,3] | .[-1] → 3 |
.[], .[]? | Every element / value (? ignores errors) | One result per element |
a | b | Pipe: feed each output of a into b | .users[] | .name |
a, b | Both outputs | .name, .age |
[ ... ], {a, b: .c} | Build an array or object | {name, city: .address.city} |
select(cond) | Keep the input only if cond is true | select(.age > 30) |
map(f), map_values(f) | Apply f to every element | map(.price * 2) |
a // b | Alternative: b when a is null, false or empty | .email // "none" |
.a = v, .a |= f, .a += 1 | Set, update or modify a path | .n |= . + 1 |
del(.a), to_entries, with_entries(f) | Delete paths, work with key/value pairs | with_entries(.key |= ascii_upcase) |
sort_by(f), group_by(f), unique_by(f) | Sort, group or de-duplicate by a key | sort_by(-.age) |
add, length, min_by(f), max_by(f) | Aggregate an array | [.[].n] | add |
reduce .[] as $x (init; update) | Fold many values into one | reduce .[] as $x (0; . + $x) |
"\(.a) and \(.b)" | String interpolation | "Hi \(.name)" |
test(), capture(), sub(), gsub() | Regular expressions | gsub("\\s+"; " ") |
@csv, @tsv, @base64, @uri, @html, @sh | Format strings (use with -r) | [.id, .name] | @csv |
.., paths, getpath(p) | Walk every value / path | [.. | numbers] |
try f catch g, f? | Handle errors | try tonumber catch 0 |
jq command-line flags
| Flag | Meaning | Typical use |
|---|---|---|
-r | Raw output: strings without quotes | Lists of names, CSV/TSV rows, shell scripts |
-c | Compact output: one result per line | Producing JSON Lines, logs |
-s | Slurp: read all inputs into one array | Counting or summing JSON Lines |
-n | Null input: start with null | Generating JSON, reading with input/inputs |
-R | Raw input: each line is a string | Parsing CSV or plain text with jq |
-S | Sort object keys in output | Stable diffs |
-j | Join: raw output without newlines | Building one long string |
--arg name v / --argjson name json | Define $name | Passing shell values into a filter safely |
Tips for writing jq filters
Build filters step by step. Start with ., add one pipe at a time and watch the output change. When a step returns many results, wrap it in [ ] to see them as one array.
Missing fields are null, not errors. .missing returns null, but .missing[] or .missing.x on a number fails. Use ?, // default or select() to guard optional data.
Quote filters in the shell. On Linux and macOS wrap the filter in single quotes: jq -r '.items[] | .name' data.json. The command shown under the output is already quoted for you.
Frequently asked questions
What is jq?
jq is a command-line JSON processor. A jq filter describes how to transform JSON: pick fields with .name, iterate arrays with .[], filter with select(), reshape with {} and [] and aggregate with functions like map, group_by, add and reduce. This playground lets you try filters without installing anything.
Is my JSON uploaded to a server?
No. The jq engine runs entirely in JavaScript inside your browser (in a background worker), so your data never leaves your device and the page keeps working offline once loaded.
Is it the same as real jq?
The engine follows jq 1.7 syntax and semantics, including paths, assignment operators, reduce, foreach, label/break, try/catch, destructuring, @formats and most built-in functions. Small differences: regular expressions use the browser's engine instead of Oniguruma, dates are handled in UTC, modules (import/include) are not available, $ENV is empty and numbers are 64-bit floats.
How do I get output without quotes?
Turn on -r (raw output). Strings are then printed as plain text, which is what you want for lists of names, @csv or @tsv rows and shell scripts. Numbers, arrays and objects are still printed as JSON.
How do I process JSON Lines (NDJSON) or several JSON documents?
Paste them one after another. jq runs the filter once per value. Turn on -s (slurp) to read all values into a single array first, for example to count or sum them with length or add.
Why do I get "Cannot iterate over null" or "Cannot index" errors?
The filter tried to use .[] or .key on a value of the wrong type, often because a field is missing (null) on some items. Add ? to ignore errors (.items[]?), use // to provide a default (.items // []) or filter first with select(.items != null).
How do I pass a value into a filter like --arg?
Open Variables and add a line such as country=US (a string, like --arg) or limit:=10 (JSON, like --argjson). Use it in the filter as $country or $limit. The command line shown below the output includes the matching --arg options.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.