
HTTPie: How to Pretty Print JSON
Updated
Learn how to pretty print JSON in the terminal using HTTPie

Before we start, make sure you have HTTPie installed on your computer and a URL that returns JSON. If you don't have HTTPie yet, you can install it with Homebrew:
brew install httpie
First, open your terminal. HTTPie pretty prints JSON for you, so to get a nicely formatted response, run this command:
http -b localhost:8080/orders.json
Just remember to replace localhost:8080/orders.json with your own URL. The -b flag only shows the response body, so the headers stay out of the way. HTTPie adds colors, indents the JSON with four spaces and sorts the keys alphabetically.
If you want a different indentation, change it with the --format-options flag:
http -b --format-options json.indent:2 localhost:8080/orders.json
One thing to know: when you pipe HTTPie into another command, it turns the formatting off. To keep it, add --pretty=format, or use --pretty=all if you want the colors too:
http -b --pretty=format localhost:8080/orders.json | head -4
If you'd rather keep the keys in their original order, just add --unsorted to the command.
