curl and jq 8 cheatsheet
curl and jq 8: jq: filter and transform JSON
14 common curl and jq 8 tasks.
Pretty-print JSON
Format JSON with indentation and colors.
curl -s https://api.example.com/users | jq .
Get a field without quotes
Output raw strings instead of JSON strings, handy in scripts.
jq -r '.name' user.json
Output compact JSON
Print each result on one line, which suits line-oriented tools.
jq -c '.users[]' data.json
Build a new object
Create objects with only the fields you want.
jq '.users[] | {id, name}' data.json
Convert to CSV
Turn arrays of values into CSV rows.
jq -r '.users[] | [.id, .name, .age] | @csv' data.json
Pass a shell variable
Use a shell value inside a jq filter without quoting problems.
jq --arg name "Ada" '.users[] | select(.name == $name)' data.json