Tip: Curl JSON Output formatting

1 min read

If you use curl http://www.changebadtogood.com/api/v1/get_recent_issues | python -mjson.tool you will see fantastic formatting of json result.
Let’s see the “before” and “after” effects.

Before:

If I hit curl http://www.changebadtogood.com/api/v1/get_recent_issues, the output would look like
[source language=”javascript”]
{“success”:true,”response”:[{“issue_id”:75,”title”:”Incomplete stormwater drains”,”lat_long”:”13.0405, 80.2337″},{“issue_id”:76,”title”:”Burning of garbage”,”lat_long”:”11.3422, 77.7275″},{“issue_id”:73,”title”:”Wading through a flood of troubles”,”lat_long”:”13.0692, 80.1914″},{“issue_id”:70,”title”:”Overflowing garbage bins raise a stink”,”lat_long”:”17.3914, 78.5065″},{“issue_id”:68,”title”:”Mosquito menace back with a vengeance”,”lat_long”:”13.0271, 80.2649″},{“issue_id”:66,”title”:”damage in drainage”,”lat_long”:”13.0475, 80.1992″},{“issue_id”:65,”title”:”this is for testing”,”lat_long”:”13.0472, 80.2008″},{“issue_id”:63,”title”:”Pothole”,”lat_long”:”12.9717, 77.5132″},{“issue_id”:61,”title”:”No white marking in speed breaker.”,”lat_long”:”10.7549, 78.69″},{“issue_id”:60,”title”:”Unclosed sewage line”,”lat_long”:”10.7546, 78.6909″}]}
[/source]

After:

If I hit curl http://www.changebadtogood.com/api/v1/get_recent_issues | python -mjson.tool, the output would look like
[source language=”javascript”]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 850 0 850 0 0 1203 0 –:–:– –:–:– –:–:– 1995
{
“response”: [
{
“issue_id”: 75,
“lat_long”: “13.0405, 80.2337”,
“title”: “Incomplete stormwater drains”
},
{
“issue_id”: 76,
“lat_long”: “11.3422, 77.7275”,
“title”: “Burning of garbage”
},
{
“issue_id”: 73,
“lat_long”: “13.0692, 80.1914”,
“title”: “Wading through a flood of troubles”
},
{
“issue_id”: 70,
“lat_long”: “17.3914, 78.5065”,
“title”: “Overflowing garbage bins raise a stink”
},
{
“issue_id”: 68,
“lat_long”: “13.0271, 80.2649”,
“title”: “Mosquito menace back with a vengeance”
},
{
“issue_id”: 66,
“lat_long”: “13.0475, 80.1992”,
“title”: “damage in drainage”
},
{
“issue_id”: 65,
“lat_long”: “13.0472, 80.2008”,
“title”: “this is for testing”
},
{
“issue_id”: 63,
“lat_long”: “12.9717, 77.5132”,
“title”: “Pothole”
},
{
“issue_id”: 61,
“lat_long”: “10.7549, 78.69”,
“title”: “No white marking in speed breaker.”
},
{
“issue_id”: 60,
“lat_long”: “10.7546, 78.6909”,
“title”: “Unclosed sewage line”
}
],
“success”: true
}
[/source]

Related posts:

2 Replies to “Tip: Curl JSON Output formatting”

  1. Really nice blog!
    1 small suggestion : Please add the following as the pre-requisite for this blog :
    sudo easy_install mjson
    or
    sudo pip install mjson.
    What would be even better is to use http://showterm.io/ and embed that into your blog!!
    Thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *