You Need To Start Using The jq Tool For All Your JSON Needs
Format and filter JSON in your terminal
The jq command line tool is definitely one of my favorite finds. If you’ve ever “prettified” JSON by copying it into VScode, I’m about to save you like 6 seconds by showing how to format (and even filter!) right in the terminal.
Download page, but on mac it’s easiest to
brew install jq
Pretty print json
First, look at the difference of this command line output:
It’s night and day. The way to do this is couldn’t be simpler, just pipe some output into jq
:
# from a curl
curl -s https://api.spacexdata.com/v3/launches/latest | jq# from a file
cat raw.json | jq
Filtering your output
Besides nicely formatting your output, jq
can also do some object and array filtering. Check out the official docs, but here’s the tl:dr; on the handiest features.