$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-print· Format raw JSON with indentation.
cat data.json | jq .
Access property· Extract a top-level field.
cat data.json | jq .name
Nested access· Walk into nested objects.
cat data.json | jq .user.address.city
Array indexing· Get the first element.
cat data.json | jq .items[0]
Array slicing· Get a subset.
cat data.json | jq .items[2:5]
Filtering
Select by condition· Filter array elements.
cat data.json | jq '.[] | select(.age > 18)'
Transformation
Map field· Extract one field from all elements.
cat data.json | jq '[.[] | .name]'
Add computed field· Create new fields.
cat data.json | jq '[.[] | {name, isAdult: (.age >= 18)}]'Merge objects· Combine objects.
cat data.json | jq '.[] | {name} + {status: "active"}'Output Formatting
Raw output· Output without quotes.
cat data.json | jq -r .name
Compact output· No newlines or indentation.
cat data.json | jq -c .items
CSV output· Convert to CSV rows.
cat data.json | jq -r '.[] | [.name, .age] | @csv'