Skip to content
>_devvkit
$devvkit learn --librarie jq-guide

jq Guide

[json][cli][data][parsing]
Universal
Install
# macOS
brew install jq

# Linux
sudo apt install jq

# Windows
winget install jq

jq is to JSON what sed is to text. It lets you slice, filter, map, and transform structured data with a concise DSL.

The . operator walks into objects, [] indexes arrays, and pipes (|) feed one filter into the next. jq queries become as natural as grep patterns.

Basic Selection

Pretty-printFormat raw JSON with indentation.
cat data.json | jq .
Access propertyExtract a top-level field.
cat data.json | jq .name
Nested accessWalk into nested objects.
cat data.json | jq .user.address.city
Array indexingGet the first element.
cat data.json | jq .items[0]
Array slicingGet a subset.
cat data.json | jq .items[2:5]

Filtering

Select by conditionFilter array elements.
cat data.json | jq '.[] | select(.age > 18)'

Transformation

Map fieldExtract one field from all elements.
cat data.json | jq '[.[] | .name]'
Add computed fieldCreate new fields.
cat data.json | jq '[.[] | {name, isAdult: (.age >= 18)}]'
Merge objectsCombine objects.
cat data.json | jq '.[] | {name} + {status: "active"}'

Output Formatting

Raw outputOutput without quotes.
cat data.json | jq -r .name
Compact outputNo newlines or indentation.
cat data.json | jq -c .items
CSV outputConvert to CSV rows.
cat data.json | jq -r '.[] | [.name, .age] | @csv'