jq Command on Linux: Parse JSON from curl, APIs and kubectl

jq command linux - custom-jq-featured.png

jq on Linux turned JSON from a niche format into everyday shell glue — DevOps engineers pipe curl, aws, and kubectl through jq to answer one question without opening a browser or spreadsheet.

Related: curl & wget,
grep,
kubectl install.

Why jq Exists

JSON is nested; jq is a filter language — like awk for structured logs and REST responses.

JSON path
filters

Install jq

Package managers ship jq on all major distros — verify version for jq 1.6+ features.

bashDebian/Ubuntu
sudo apt update && sudo apt install -y jq
jq --version
apt install jq
version

Select Fields

Dot notation walks objects; [] expands arrays.

bashpretty
curl -s https://api.github.com/repos/torvalds/linux | jq '.name, .stargazers_count'
.name
arrays

Filters: select and map

Narrow lists without writing Python one-liners.

bashfilter
curl -s https://httpbin.org/json | jq '.slideshow.slides | map(.title)'
select()
map()

Pipe Real Commands

Same pattern for cloud CLIs and Kubernetes — always validate JSON first.

bashpods
kubectl get pods -A -o json | jq -r '.items[] | select(.status.phase!="Running") | .metadata.name'
kubectl | jq
curl | jq

Errors and Scripting

Invalid JSON makes jq exit non-zero — ideal for cron health checks.

WarningNever eval jq output into shell — use -r for safe strings and quote variables.
exit code
? operator

Practice on a Live Endpoint

Pick one field your monitor cares about; fail the script if it is missing.

bashassert
status=$(curl -fsS https://httpbin.org/status/200 | jq -r '.status // empty')
[ "$status" = "200" ] || exit 1
health check
assert

Quick Reference

  • curl -s URL | jq '.field' for APIs
  • -r prints raw strings (no quotes)
  • Use in scripts: check jq exit code on bad JSON

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.