DEV Community

Alex Chen
Alex Chen

Posted on

Quick Tip: Debug Any API Response with `curl | python -m json.tool` (No jq Needed)

Quick Tip

jq is great until you're SSH'd into a minimal container that doesn't have it. Python is already there:

curl -s https://api.github.com/users/octocat | python3 -m json.tool
Enter fullscreen mode Exit fullscreen mode

Add -i to see status + headers inline — invaluable when an API silently 429s you:

curl -si https://api.example.com/data | head -20
Enter fullscreen mode Exit fullscreen mode

Need just one field, no jq? json.tool won't filter, but this one-liner will:

curl -s https://api.github.com/users/octocat | python3 -c "import json,sys; print(json.load(sys.stdin)['public_repos'])"
Enter fullscreen mode Exit fullscreen mode

And the one that saves me weekly — diff two environments' responses:

diff <(curl -s https://staging.api.com/health | python3 -m json.tool --sort-keys) \
     <(curl -s https://prod.api.com/health | python3 -m json.tool --sort-keys)
Enter fullscreen mode Exit fullscreen mode

--sort-keys makes the diff stable across key-order changes. Zero installs, works everywhere Python 3 lives.

Powered by MonkeyCode (free tier): https://ly.cyberserval.tech/iIETXiF

What's your go-to stdlib trick that replaces a tool everyone else installs first?

Top comments (0)