Python JSON.Tool

Some CLIs will spit out JSON as its response. Those types of response tends to be jumbled into a single line with poor formatting, making them humanly impossible to read.

Luckily the Python Library has a wonderful JSON tool that can help format the output into a readable manner.

Tools Needed

  • Python v2.7+

Usage

python -m json.tool <filename>

Example

python -m json.tool my-json-file.json

Example Input

{ "data":{"days":5,"world":{"name":"earth","neighbours": ["sun","mercury","venus"] }}}

Example Output

{
    "data": {
        "days": 5,
        "world": {
            "name": "earth",
            "neighbours": [
                "sun",
                "mercury",
                "venus"
            ]
        }
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s