[PYTHON] One liner that formats JSON to make it easier to see

Overview

A one-liner that formats JSON to make it easier to see. If you have a Mac with python installed, you can use it immediately from the terminal.

command

curl -s "<url>"|python -m json.tool

Before plastic surgery

$ curl -s "https://auctions.yahooapis.jp/AuctionWebService/V2/json/search?appid=dj0zaiZpPU1aMWppaDVwUFFSTSZzPWNvbnN1bWVyc2VjcmV0Jng9MTc-&results=20&query=ipad"
loaded({"ResultSet":{"@attributes":{"totalResultsAvailable":"32269","totalResultsReturned":"20","firstResultPosition":"1"},"Result":{"UnitsWord":["iPad air2","iPad MINI","iPad Pro","iPad mini4","iPad AIR"],"Item":[{"AuctionID":"f181174186","Title":"\u25cf\u65b0\u54c1\u540c\u69d8\u25cfiPad mini Retina Wi-Fi 32GB \u30b7\u30eb\u30d0\u30fc\u25cf","CategoryId":"2084259337","Seller":{"Id":"mtm_store333","ItemListUrl":"http:\/\/auctions.yahooapis.jp\/AuctionWebService\/V2\/sellingList?sellerID=mtm_store333","RatingUrl":"http:\/\/auctions.yahooapis.jp\/AuctionWebService\/V1\/ShowRating?id=mtm_store333"},"ItemUrl":"http:\/\/auctions.yahooapis.jp\/AuctionWebService\/V2\/auctionItem?auctionID=f181174186","AuctionItemUrl":"http:\/\/page6.auctions.yahoo.co.jp\/jp\/auction\/f181174186","Image":"http:\/\/auctions.c.yimg.jp\/images.auctions.yahoo.co.jp\/image\/dr147\/auc0206\/users\/2\/9\/0\/8\/mtm_store333-thumb-1
  :

After plastic surgery

$ curl -s "https://auctions.yahooapis.jp/AuctionWebService/V2/json/search?appid=dj0zaiZpPU1aMWppaDVwUFFSTSZzPWNvbnN1bWVyc2VjcmV0Jng9MTc-&results=20&query=ipad"|sed -e "s/^loaded(//" -e "s/)$//"|python -m json.tool
{
    "ResultSet": {
        "@attributes": {
            "firstResultPosition": "1",
            "totalResultsAvailable": "32269",
            "totalResultsReturned": "20"
        },
        "Result": {
            "Item": [
                {
                    "AuctionID": "f181174186",
                    "AuctionItemUrl": "http://page6.auctions.yahoo.co.jp/jp/auction/f181174186",
                    "BidOrBuy": "24800.00",
                    "Bids": "0",
                    "CategoryId": "2084259337",
                    "CharityOption": {
                        "Proportion": "0"
                    },
  :

Recommended Posts

One liner that formats JSON to make it easier to see
You who color the log to make it easier to see
Make it easier to test programs that work with APIs with vcrpy
One liner to make Lena images with scipy
Expand devicetree source include to make it easier to read
One liner to talk somewhere
A story that makes it easier to see Model debugging in the Django + SQLAlchemy environment
I tried to make a site that makes it easy to see the update information of Azure
Join csv normalized by Python pandas to make it easier to check
I wrote Django commands to make it easier to debug Celery tasks
Easy to see difference of json
I felt that mock for object is easier to see via patch.
Gorilla judgment machine, gorilla! !! Tried to make it!
Tips to make Python here-documents easier to read
Deep learning dramatically makes it easier to see the time-lapse of physical changes