Copy · paste · pipe
jq one-liners you can actually paste.
Ready-to-run jq recipes for the JSON tasks you actually do — filter with
select(), reshape with map(), build objects, sort and group arrays, and
spit out CSV — each with example input and output so you can see exactly what it does.
15 recipes
- Basics Access Fields & Nested Keys with jq (.a.b.c) Pull a single value out of JSON — top-level keys, nested objects, array elements — and avoid 'Cannot index null' errors. Copy-paste jq.
- Basics Install jq (Linux, macOS, Windows) Install the jq JSON processor on every platform — apt, dnf, brew, winget, scoop — plus how to check the version. Copy-paste.
- Basics Loop Over a JSON Array with jq (.[]) Iterate every element of a JSON array (or every value of an object) with .[], pull one field from each, and re-collect into an array. Copy-paste jq.
- Basics Pretty-Print & Minify JSON with jq (. and -c) Format ugly JSON, minify it to one line, sort keys, and pretty-print a curl/API response. Copy-paste jq.
- Filtering Filter an Array of Objects by a Nested Key (jq) Select objects by a value buried in a nested object or inner array with jq — including 'array contains' and 'any sub-item matches'. Copy-paste.
- Filtering jq has(), contains() & test() (Key Exists, Substring, Regex) Check whether a key exists, whether a value contains another, and match strings with regex in jq. Copy-paste with examples.
- Filtering Filter JSON with jq select() (by Value or Condition) Keep only the array elements that match a condition using jq select() — numbers, strings, booleans, AND/OR. Copy-paste with example output.
- Transform Add, Delete & Rename Keys with jq Add a field, remove one or many keys with del(), and rename keys (single or by pattern) using jq. Copy-paste with output.
- Transform Build a New Object with jq {a: .x, b: .y} Reshape JSON into a new object — pick fields, rename, compute values, shorthand keys, dynamic keys. Copy-paste jq with output.
- Transform Transform Each Item with jq map() Apply an expression to every element of an array with jq map() — pull a field, do math, reshape each object. Copy-paste with output.
- Arrays Array length, flatten & slice with jq Count elements, flatten nested arrays, slice ranges, grab first/last, and sum with jq. Copy-paste with output.
- Arrays Sort, Unique & Group with jq (sort_by, unique, group_by) Sort an array of objects by a field, dedupe, and group records by a key with jq — plus count-per-group. Copy-paste with output.
- Formats Raw String Output & Interpolation in jq (-r) Print strings without quotes (-r), build strings with interpolation \(.x), join arrays, and emit shell-ready lines with jq. Copy-paste.
- Formats Convert JSON to CSV/TSV with jq (@csv, @tsv) Turn an array of JSON objects into CSV or TSV with jq — with a header row, selected columns, and proper quoting. Copy-paste.
- Advanced jq --arg, slurp (-s) & recursive descent (..) Pass shell variables into jq safely with --arg/--argjson, combine multiple inputs with slurp (-s), and search any depth with recursive descent (..). Copy-paste.
Why this exists
You know what you want. You don't remember the jq for it.
jq is unreasonably powerful, but the syntax for "filter this array of objects by a nested field" or "turn this into CSV" never sticks — so you re-derive it, or paste a half-right snippet from a six-year-old answer. jqsnap.pages.dev is the opposite: each recipe is a focused, copy-paste filter for one real task, with sample input and the exact output it produces, so you can confirm it before you run it on your data.
How it works
Find the task, copy the filter, pipe your JSON
- Pick a recipe. Browse by task in the full recipe list.
- Copy the filter. Every
jqcommand has a one-click copy button. - Pipe your data.
cat data.json | jq '...'orcurl ... | jq '...'— each recipe shows example input and output.
FAQ
Frequently asked questions
Are these jq recipes free?
Yes. Every recipe on jqsnap.pages.dev is free to read and copy, with no account, paywall, or sign-up. Some outbound links (for example to dev tools or hosting) may be affiliate links, which never change the price you pay.
Do I need jq installed?
Yes — jq is a small standalone binary. Install it with "brew install jq" (macOS), "sudo apt install jq" (Debian/Ubuntu), or "winget install jqlang.jq" (Windows). The install recipe covers every platform.
How do I pipe a curl / API response into jq?
Pipe stdout straight in: "curl -s https://api.example.com/users | jq '.'". jq reads JSON on stdin, applies your filter, and prints the result. Every recipe shows the filter; prefix it with your curl or cat.
How do I pass a shell variable into a jq filter?
Use --arg (string) or --argjson (number/bool/JSON): "jq --arg name \"$USER\" 'select(.owner == $name)'". Never interpolate shell variables directly into the filter string — see the --arg recipe.
I get "jq: error ... Cannot index ... with ..." — why?
Usually you indexed into null or the wrong type (e.g. .a.b where .a is missing). Use the optional operator "?" (".a.b?") or "// empty" to skip missing paths instead of erroring. The access-fields recipe shows the safe forms.
Which jq version do these target?
jq 1.6 and 1.7+. A few newer builtins (like pick, abs, or improved regex) need 1.7 — recipes note when a feature is version-specific. The core filters here work everywhere.