Pretty print your json

1 min read

Due to its simplicity compared to other formats like XML, JSON these days is completly ruling the marking of remote APIs, like REST.

Let’s have a look at one small problem which occurs quite often:

curl ""

{"metaData":{"apiVersion":"0.2","warning":"ACHTUNG: Bitte vor ernsthafter Nutzung kontaktieren, um bei API-Änderungen informiert zu werden","copyright":"Copyright (C) 2014 Daniel Naber (","license":"GNU LESSER GENERAL PUBLIC LICENSE Version 2.1","source":"","date":"Sun Oct 18 09:20:29 CEST 2015"},"synsets":[{"id":292,"categories":[],"terms":[{"term":"Erprobung"},{"term":"Probe"},{"term":"Prüfung"},{"term":"Test"},{"term":"Versuch"}]},{"id":4398,"categories":[],"terms":[{"term":"Kontrolle"},{"term":"Leistungsnachweis"},{"term":"Prüfung"},{"term":"Test"}]},{"id":5752,"categories":[],"terms":[{"term":"Klassenarbeit"},{"term":"Klausur"},{"term":"Lernerfolgskontrolle"},{"term":"Prüfung"},{"term":"Schularbeit"},{"term":"Schulaufgabe"},{"term":"Test"},{"term":"Arbeit","level":"umgangssprachlich"}]},{"id":9138,"categories":[],"terms":[{"term":"Experiment"},{"term":"Probelauf"},{"term":"Studie"},{"term":"Test"},{"term":"Testballon"},{"term":"Testlauf"},{"term":"Trockenlauf"},{"term":"Trockentest"},{"term":"Versuch"}]}]}⏎

Pretty print

So you are either a guru or extremly motivated to remember the open braces for your own, otherwise you need help to read the JSON properly. One small trick which is pretty useful with the following helper tool:

curl "" | python -m json.tool

    "metaData": {
        "apiVersion": "0.2",
        "copyright": "Copyright (C) 2014 Daniel Naber (",
        "date": "Sun Oct 18 09:22:37 CEST 2015",
        "license": "GNU LESSER GENERAL PUBLIC LICENSE Version 2.1",
        "source": "",
        "warning": "ACHTUNG: Bitte vor ernsthafter Nutzung kontaktieren, um bei API-\u00c4nderungen informiert zu werden"


This comes out of the box with python.


Another cool package is pygmentize, which colorizes the output. To install use

easy_install|pip|conda install  pygmentize

Then you pip that at the end and you get colored output:

curl "" | python -m json.tool | pygmentize

For more sophisticated usecases checkout out [Postman][postman].