How to Use jq Online — 10 Examples That Run in Your Browser
jq has been downloaded over 50 million times because it solves a real problem: querying and transforming JSON from the command line without writing a script. This tutorial covers 10 practical jq patterns — from simple field extraction to group-by aggregations — with examples you can paste directly into a terminal or an online playground.
What is jq and How to Install It
jq is a command-line JSON processor written in C. It reads JSON from stdin or a file, applies a filter expression, and writes the result to stdout. The project is maintained at github.com/jqlang/jq.
The . filter is the identity — it pretty-prints the input. Every other filter builds on this foundation.
10 Practical jq Examples
Access a top-level key with .fieldname. Nested keys with .parent.child.
Use object construction {key: .value} to build a new object from selected fields.
Use select() inside map() or .[] to filter array elements. This keeps only users with admin role.
Extract one field from every object in an array using [.[] | .field] or the shorthand [.[].field].
Combine map() and add to sum a numeric field across an array.
group_by(.field) returns an array of arrays, each group sharing the same value. Combine with to_entries for labelled output.
sort_by(.field) returns the array sorted ascending. Append | reverse for descending.
Use [paths(scalars)] to get all paths, or flatten arrays with the flatten builtin.
del(.key) removes a key from an object. Works on nested paths too: del(.user.password).
Combine multiple filters to reshape a complex API response into a simpler structure.
jq Cheat Sheet
| Filter | Description |
|---|---|
. | Identity — pretty-print input |
.foo | Get value of key foo |
.foo.bar | Get nested key bar inside foo |
.foo? | Get foo, return null if it doesn't exist (no error) |
.[] | Iterate array or object values |
.[0] | First element of array |
.[-1] | Last element of array |
.[2:5] | Slice array from index 2 to 4 |
| | Pipe: pass left output to right filter |
, | Output multiple values |
length | Length of string, array, or object |
keys | Array of object keys |
values | Array of object values |
has(key) | True if object has key |
in(obj) | True if value is a key in obj |
map(f) | Apply filter f to each array element |
select(bool) | Keep input if bool is true |
empty | Produce no output |
add | Sum numbers or concatenate arrays/strings |
any / all | Boolean on array elements |
group_by(f) | Group array by field value |
unique_by(f) | Deduplicate by field |
sort_by(f) | Sort array by field |
min_by(f) / max_by(f) | Min/max of array by field |
to_entries / from_entries | Convert object to/from [{key, value}] |
with_entries(f) | map on to_entries then from_entries |
del(.foo) | Delete key from object |
strings / numbers / booleans / arrays / objects / nulls | Type filters |
type | Returns the type string |
@base64 / @uri / @csv / @tsv / @json | Format output as different encodings |
Tips for Writing jq Filters
Use -r for raw string output
By default, jq wraps strings in quotes. Add -r (--raw-output) when you need plain strings: echo '{"name":"Jane"}' | jq -r '.name' outputs Jane not "Jane".
Use -c for compact output
-c (--compact-output) removes whitespace from the output. Useful when piping jq output to another command.
Null-safe access with ?
Add ? to any accessor to suppress errors when the key doesn't exist: .user.address?.city returns null instead of erroring if address is missing.
Test filters incrementally
Build complex filters by adding one pipe stage at a time. Verify each stage's output before adding the next.
Use @json to embed JSON in a string
If you need to produce a JSON string containing another JSON object, use @json: {payload: (.data | @json)}.
Format and Inspect jq Output
After running jq locally, paste the output into our JSON formatter to explore the structure, validate syntax, and minify for use in scripts.
For an online jq playground, jqplay.org runs jq in the browser.
Open JSON Formatter