Skip to main content

You are here

Using Python to Output Pretty Looking JSON

Every once and awhile, theirs occasions that I have a giant glob of JSON data that I want to easily read it's data. Normally I opted to use http://jsonlint.com/. The problem is whenever I use http://jsonlint.com/, I always have to be sure the JSON data doesn't include anything confidential. I was happy to learn that you can easily use the json library in Python to accomplish essentially the same thing.

For example:

alpha03:~ tony$ cat test.json
{"employees":[{"firstName":"John", "lastName":"Doe"},{"firstName":"Anna", "lastName":"Smith"},{"firstName":"Peter", "lastName":"Jones"}]} 
alpha03:~ tony$ python -m json.tool < test.json
{
    "employees": [
        {
            "firstName": "John",
            "lastName": "Doe"
        },
        {
            "firstName": "Anna",
            "lastName": "Smith"
        },
        {
            "firstName": "Peter",
            "lastName": "Jones"
        }
    ]
}
Premium Drupal Themes by Adaptivethemes