23rd December 2014 - 5 minutes read time
JSON is a very common data format, but reading it can be a little difficult, especially if the JSON contains very little white space. If you have Python 2.6 or above you have use the json.tool to format the JSON so that you can read it correctly. This is also a good way to validate JSON strings that you have had to hand edit before they cause errors upstream.
If you have a file called file.json, which contains a bunch of JSON output, you can use Python to format this into a readable structure in the following way.
python -m json.tool file.json
You can also write this output directly into a file, in this case called formatted.json.
python -m json.tool file.json > formatted.json
The most common use of this tool is to pipe JSON to it from the command line (either directly or via a script).