Parse and Transform JSON with jq
Pull values out of JSON, filter arrays, and reformat output using jq's filter language — sed/awk for the JSON age.
Run jq '.field' file.json to extract a value, jq '.items[].name' to list array elements, and jq -r '.name' to get raw strings without quotes.
01Command
Command
$ curl -s https://api.github.com/repos/torvalds/linux | jq '.stargazers_count, .description'
jq -r '.items[].name' data.json02What it does
jq reads JSON and applies a filter expression: .foo.bar digs into nested objects, .[] iterates arrays, and pipes inside filters chain transformations the way shell pipes do. -r prints raw strings (dropping the JSON quotes) so output can feed straight into other commands, and --slurp or -c handles multi-document streams. It's the standard glue between curl APIs and shell scripts — curl ... | jq '.data[].id' replaces a dozen lines of Python.
03Risk
!Warning: Unquoted jq filters on the command line get eaten by the shell — always single-quote the expression, since '.items[]' with double quotes can glob-expand.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- jq READMEEvidence: Describes jq as a lightweight command-line JSON processor with a filter-based language.
- jq(1) — Linux man pageEvidence: jq man page: 'jq - Command-line JSON processor' documenting filters, field access .foo, iteration .[], and -r raw output.
Last verified: 2026-09-17 · Category: Developer