You Need To Start Using The jq Tool For All Your JSON Needs

Format and filter JSON in your terminal

Mike Cronin
Level Up Coding
Published in
3 min readJul 20, 2020

--

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:

Unorganized raw JSON output as text, vs nicely formatted and highlighted JSON output from jq

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.

Grab specific property or index

--

--

I’m Mostly Focused on JS and web development, but anything coding related is fair game