How to Parse JSON in Bash with jq
Bash has no built-in JSON parser — use jq, the standard command-line JSON processor. Pipe JSON into jq with a filter to extract or transform values.
Extract a field
Pipe JSON to jq and select a path. Use -r for raw (unquoted) string output.
bash
echo '{"name":"Ada","roles":["admin","dev"]}' | jq -r '.name'
# Ada
curl -s https://api.example.com/user | jq -r '.roles[0]'Filter and map arrays
jq filters transform arrays inline — map fields, select by condition, and more.
bash
# names of active users
jq -r '.users[] | select(.active) | .name' data.json
# array of ids
jq '[.items[].id]' data.jsonPretty-print and validate
jq pretty-prints by default; use it to format or to check that a file is valid JSON.
bash
jq . data.json # pretty-print
jq empty data.json && echo OK # exit 0 if valid JSON