Filter, reshape and stream JSON from a shell.
jq
Extract one field from a stream
curl -s https://api.example.com/items | jq -r '.items[].name'
-r writes raw strings instead of quoted JSON. Without it names come back wrapped in escape sequences.
Filter before you extract
jq -r '.items[] | select(.state == "ready") | .id'
Fail loudly instead of printing null
jq -e -r '.token' config.json
-e sets the exit status from the result. A missing key becomes exit 4, which stops a script that would otherwise carry null into the next command.
Work with objects without a schema
jq 'keys' payload.json
jq 'to_entries | map(select(.value > 100)) | from_entries' metrics.json
jq exits 0 on
null unless -e is set. Scripts that chain jq output into another command should almost always use -e.