2011/11/01

terminal で json pretty print

terminalからweb apiを呼んで返ってきたjsonを見るときに。pythonはだいたいどこでも入ってるし。
python -m json.tool
wget -O - http://foo:piyo@hogehoge.com/api/fuga | python -m json.tool

例えばこんな感じ。
% wget -O - "https://api.twitter.com/1/statuses/user_timeline.json?id=valvallow&count=1" 2> /dev/null | python -mjson.tool
[
    {
        "contributors": null,
        "coordinates": null,
        "created_at": "Tue Nov 01 15:04:22 +0000 2011",
        "favorited": false,
        "geo": null,  
        "id": 131386101536526337,
        "id_str": "131386101536526337",
        "in_reply_to_screen_name": "sasagawa888",
        "in_reply_to_status_id": 131385453638201344,
        "in_reply_to_status_id_str": "131385453638201344",
        "in_reply_to_user_id": 236352281,
        "in_reply_to_user_id_str": "236352281",
        "place": null,
        "retweet_count": 0, 
        "retweeted": false, 
        "source": "twicli", 
        "text": "@sasagawa888 \u305d\u3046\u3067\u3059\uff3e\uff3e\uff1b", 
        "truncated": false, 
        "user": {
            "contributors_enabled": false, 
            "created_at": "Mon May 14 04:57:45 +0000 2007", 
            "default_profile": false, 
            "default_profile_image": false, 
            "description": "S\u5f0f\u304c\u597d\u304d\u3002\u660e\u65e5\u304b\u3089\u672c\u6c17\u51fa\u3059\u3002\u306e\u3093\u3073\u308a\u751f\u6d3b\u3057\u305f\u3044\u3002", 
            "favourites_count": 2686, 
            "follow_request_sent": false, 
            "followers_count": 1648, 
            "following": true, 
            "friends_count": 1395, 
            "geo_enabled": false, 
            "id": 6023392,
            "id_str": "6023392",
            "is_translator": false,
            "lang": "ja",
            "listed_count": 163,
            "location": "kumamoto",
            "name": "\u3057\u3083\u308c\u3053\u3046\u3079\u4e59",
            "notifications": false,
            "profile_background_color": "FFFFFF",
            "profile_background_image_url": "http://a0.twimg.com/profile_background_images/655452/Half_docro.jpg",
            "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/655452/Half_docro.jpg",
            "profile_background_tile": false,
            "profile_image_url": "http://a0.twimg.com/profile_images/557761803/dokuro33whitebig_normal.JPG",
            "profile_image_url_https": "https://si0.twimg.com/profile_images/557761803/dokuro33whitebig_normal.JPG",
            "profile_link_color": "000000",
            "profile_sidebar_border_color": "000000",
            "profile_sidebar_fill_color": "D3D3D3",
            "profile_text_color": "000000",
            "profile_use_background_image": true,
            "protected": false,
            "screen_name": "valvallow",
            "show_all_inline_media": false,
            "statuses_count": 30993,
            "time_zone": "Tokyo",
            "url": "http://valvallow.blogspot.com/",
            "utc_offset": 32400,
            "verified": false
        }
    }
]
webならここがいい。

0 件のコメント:

コメントを投稿