jq
JSON Processing

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.

April 29, 2026
10 min read
PDF Mavericks Team

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.

# Install
brew install jq # macOS
sudo apt-get install jq # Ubuntu/Debian
winget install jqlang.jq # Windows
# Verify
jq --version # jq-1.7.1
# Basic usage
echo '{"name":"Jane","age":28}' | jq .

The . filter is the identity — it pretty-prints the input. Every other filter builds on this foundation.

10 Practical jq Examples

1
Extract a Single Field

Access a top-level key with .fieldname. Nested keys with .parent.child.

Input JSON
{"name": "Jane", "age": 28, "city": "Mumbai"}
jq filter
.name
Output
"Jane"
2
Extract Multiple Fields into a New Object

Use object construction {key: .value} to build a new object from selected fields.

Input JSON
{"id": 42, "name": "Jane", "email": "jane@x.com", "password": "secret"}
jq filter
{id: .id, name: .name, email: .email}
Output
{ "id": 42, "name": "Jane", "email": "jane@x.com" }
3
Filter an Array by Condition

Use select() inside map() or .[] to filter array elements. This keeps only users with admin role.

Input JSON
[{"name":"Jane","role":"admin"}, {"name":"Bob","role":"viewer"}, {"name":"Ali","role":"admin"}]
jq filter
.[] | select(.role == "admin")
Output
{"name":"Jane","role":"admin"} {"name":"Ali","role":"admin"}
4
Map a Field Across an Array

Extract one field from every object in an array using [.[] | .field] or the shorthand [.[].field].

Input JSON
[{"name":"Jane"}, {"name":"Bob"}, {"name":"Ali"}]
jq filter
[.[].name]
Output
["Jane", "Bob", "Ali"]
5
Sum a Numeric Field

Combine map() and add to sum a numeric field across an array.

Input JSON
[{"item":"A","qty":5}, {"item":"B","qty":12}, {"item":"C","qty":3}]
jq filter
[.[].qty] | add
Output
20
6
Group By a Field

group_by(.field) returns an array of arrays, each group sharing the same value. Combine with to_entries for labelled output.

Input JSON
[{"name":"A","dept":"eng"}, {"name":"B","dept":"sales"}, {"name":"C","dept":"eng"}]
jq filter
group_by(.dept)
Output
[[{"name":"A","dept":"eng"}, {"name":"C","dept":"eng"}], [{"name":"B","dept":"sales"}]]
7
Sort an Array by a Field

sort_by(.field) returns the array sorted ascending. Append | reverse for descending.

Input JSON
[{"name":"C","score":80}, {"name":"A","score":95}, {"name":"B","score":72}]
jq filter
sort_by(.score) | reverse
Output
[{"name":"A","score":95}, {"name":"C","score":80}, {"name":"B","score":72}]
8
Flatten Nested JSON

Use [paths(scalars)] to get all paths, or flatten arrays with the flatten builtin.

Input JSON
[[1, 2], [3, [4, 5]], [6]]
jq filter
flatten
Output
[1, 2, 3, 4, 5, 6]
9
Delete a Key

del(.key) removes a key from an object. Works on nested paths too: del(.user.password).

Input JSON
{"name":"Jane", "email":"jane@x.com", "password":"secret"}
jq filter
del(.password)
Output
{ "name": "Jane", "email": "jane@x.com" }
10
Transform and Reshape JSON

Combine multiple filters to reshape a complex API response into a simpler structure.

Input JSON
{"data": {"users": [ {"id":1,"full_name":"Jane D"}, {"id":2,"full_name":"Bob S"} ]}}
jq filter
.data.users | map({id, name: .full_name})
Output
[{"id":1,"name":"Jane D"}, {"id":2,"name":"Bob S"}]

jq Cheat Sheet

FilterDescription
.Identity — pretty-print input
.fooGet value of key foo
.foo.barGet 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
lengthLength of string, array, or object
keysArray of object keys
valuesArray 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
emptyProduce no output
addSum numbers or concatenate arrays/strings
any / allBoolean 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_entriesConvert 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 / nullsType filters
typeReturns the type string
@base64 / @uri / @csv / @tsv / @jsonFormat 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