Installing simplejson on Python 2.4 for CentOS 5.7

I tried to install a few different JSON printers on a CentOS 5.7 box I was trying to use, but nothing was compiling. I checked Stack Overflow and tried a few of the python suggestions, but none of those worked either. I realised that it’s because I’m running Python 2.4, and that has no JSON tools built in. Once I downloaded and installed simplejson everything worked fine.

Installing simplejson 2.0.9

tar xzvf simplejson-2.0.9.tar.gz
cd simplejson-2.0.9
sudo python install

Creating prettyjson

We want to be able to pipe content into our pretty printer easily. To do this, create a new file named prettyjson somewhere in your $PATH and save the following content into it:

#!/usr/bin/env python
Convert JSON data to human-readable form.

(Reads from stdin and writes to stdout)

import sys
import simplejson as json

print json.dumps(json.loads(, indent=4)

Once you’ve saved it, run chmod +x /path/to/prettyjson and you’re ready to start using it


echo '{"a":"b"}' | prettyjson

You can pipe any input into it, e.g:

script_that_outputs_json | prettyjson

December 09, 2012

Quick Fix