Pretty-Printing JSON with Python’s JSON Tool
Today’s quick tip is something that was widely retweeted after my “Debugging HTTP” talk at the ever-fabulous WhiskyWeb conference last weekend. When working with JSON on the commandline, here’s a quick tip for showing the JSON in a nicer format:
curl http://api.joind.in | python -mjson.tool
You need python installed, but the JSON extension is probably included, and that’s all you need for this tool. The result is something like:
You can also use this approach to present JSON data that has been captured to another file, for example, it’s a handy trick that I use often when developing something with JSON as a data format.
I’ve been using HTTPie (https://github.com/jkbr/httpie) for a while, and it uses either the json extension or pygments to format and colorize JSON output. Having the output formatted is tremendously useful for readability and debugging!
That’s a great tip, thanks for adding it :)
I’ve been using http://www.jsonprettyprint.net if I just needed something quick when playing around with different API results.
Oh that looks useful, thanks for sharing!
7 year glitch! I just stumbled across this post when searching something like ‘lorna http tools’ to recap on your stimulatingly super presentation at the virtual Python North West Meetup yesterday! Still a great tool 7 years later, and history repeated itself when HTTPIE got mentioned too.
I just deployed my blog today also, I wonder what it will look like 7 years from now? I hope as great as yours does now.
I hope so too! I refer to even the oldest posts super often, even now. And yep, definitely double checked this one when I was presenting HTTP to a python group this week :) I have just added the tools list with links to the README on the planet app so check this out if you’d like more: https://github.com/lornajane/flask-planets-and-webhooks/#http-tools