Luke Oliff.

TIL: Parsing JSON API Responses With jq in the Terminal

·TIL·1 min read·Luke Oliff

Every API returns JSON. Reading it raw in the terminal is a wall of text with no line breaks. jq fixes that.

curl -s https://api.example.com/v1/calls | jq '.'

The dot is the identity filter. It pretty-prints the response with syntax highlighting. You can drill into specific fields.

curl -s https://api.example.com/v1/calls | jq '.data[] | {id: .id, status: .status}'

I wrote a lot of Vonage API tutorials in 2019. Every single one started with a curl command piped through jq. It turned API exploration from a chore into something you can do in two keystrokes.

How do I install jq?

brew install jq

Can jq filter arrays?

Yes. .[] | select(.status == "completed") returns only matching items.