curl -s https://api.github.com/repos/jqlang/jq | jq '.'A foundational pattern for API inspection.
Real-world jq commands for APIs, cloud tooling, DevOps output, reporting, logs, and shell scripting.
Use jq with HTTP APIs and JSON responses.
curl -s https://api.github.com/repos/jqlang/jq | jq '.'A foundational pattern for API inspection.
curl -s https://api.github.com/repos/jqlang/jq | jq -r '.full_name'Use `-r` for plain shell-friendly output.
curl -s https://api.github.com/orgs/github/repos?per_page=5 | jq -r '.[].full_name'Very common for quick reporting from API arrays.
curl -s https://api.github.com/orgs/github/repos?per_page=5 | jq -r '.[] | [.name, .stargazers_count] | @csv'Excellent for spreadsheet exports and ad hoc reports.
curl -s https://api.github.com/orgs/github/repos?per_page=20 | jq '.[] | select(.language == "Go") | {name, language}'A good example of combining `select()` with object projection.
Use jq with common DevOps tools that emit JSON.
aws ec2 describe-instances | jq -r '.Reservations[].Instances[].InstanceId'This pattern appears constantly in shell automation.
aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.State.Name == "running") | {id: .InstanceId, type: .InstanceType}'Great for lightweight audits without crafting a JMESPath query.
kubectl get pods -o json | jq -r '.items[].metadata.name'Perfect for loops and quick visibility.
kubectl get pods -o json | jq '.items[] | select(.status.phase == "Running") | .metadata.name'Useful for triage and operational scripts.
docker inspect my-container | jq -r '.[0].NetworkSettings.IPAddress'A classic jq + Docker recipe.
terraform show -json | jq -r '.values.root_module.resources[].address'Excellent for inventorying state contents.
Analyze logs and create shell-friendly reports.
cat app.log | jq -r '.level'Works when each log line is a JSON object.
cat app.log | jq 'select(.level == "error")'Simple and effective for local debugging.
cat app.log | jq -s 'group_by(.level) | map({level: .[0].level, count: length})'Useful for operational summaries and postmortems.
cat app.log | jq -r '[.timestamp, .level, .message] | @tsv'Great for quick grep-friendly tabular output.
echo '[{"name":"alice","score":90},{"name":"bob","score":85}]' | jq -r '.[] | "| (.name) | (.score) |"'Handy for docs, PR comments, and status reports.
APP_NAME=cheatsheet ENV=prod jq -n --arg app "$APP_NAME" --arg env "$ENV" '{app: $app, env: $env}'A strong pattern for shell scripting and automation.
Pass values from the shell safely into jq.
name=alice; jq -n --arg name "$name" '{name: $name}'Use `--arg` for shell strings.
count=42; jq -n --argjson count "$count" '{count: $count}'Use `--argjson` when the value should remain JSON, not a string.
jq --slurpfile cfg config.json '.items[] | {name, config: $cfg[0]}' data.jsonUseful for joins between documents or config-driven transforms.
jq --argfile cfg config.json '{config: $cfg, data: .}' data.jsonUse when you need a single parsed JSON document as context.
echo '{"healthy":true}' | jq -e '.healthy' > /dev/null`-e` is excellent for shell conditions and CI checks.