> ## Content Index
> Fetch the complete content index at: https://www.binarysludge.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Easy CLI JSON Formatting
- URL: https://www.binarysludge.com/2012/11/09/easy-cli-json-formatting/
- Published: 2012-11-09T12:00:06.000Z
- Updated: 2012-11-09T11:55:41.000Z
- Author: Andrew Martin
- Tags: cURL, bash, JSON, Python, system adminstration, #Import 2026-10-22 12:56

Command line JSON interpretation can be confusing. Python's [json](http://docs.python.org/2/library/json.html?ref=binarysludge.com) library (2.6+) provides a simple prettifier:

$ echo '{"json":"obj"}' | python -mjson.tool
{
    "json": "obj"
}

Or facetiously (from the obligatory [Internet Chuck Norris Database](http://www.icndb.com/?ref=binarysludge.com)):

$ curl -s "http://api.icndb.com/jokes/random?firstName=Andrew&lastName=Martin" | python -mjson.tool
{
    "type": "success",
    "value": {
        "categories": [
            "nerdy",
            "chuck norris"
        ],
        "id": 528,
        "joke": "Andrew Martin doesn't use GUI, he prefers COMMAND line."
    }
}

This can be wrapped in a handy shell function:

$ function parse_url_json() 
{
    curl -s "$@" | python -mjson.tool
}

$ parse_url_json 'http://api.icndb.com/jokes/random?firstName=Andrew&lastName=Martin'

2.5 users can install the [simplejson](http://pypi.python.org/pypi/simplejson/?ref=binarysludge.com) library.