JSON を treeコマンド風に表示する gem を作った

More than 1 year has passed since last update.

JSON を tree コマンドっぽく表示出来ます。

http://jsonplaceholder.typicode.com/users/1

{

"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
}

これがこうなります

curl http://jsonplaceholder.typicode.com/users/1 | jt

出力

root

├──── "id": 1
├──── "name": "Leanne Graham"
├──── "username": "Bret"
├──── "email": "Sincere@april.biz"
├──── "address"
│ ├──── "street": "Kulas Light"
│ ├──── "suite": "Apt. 556"
│ ├──── "city": "Gwenborough"
│ ├──── "zipcode": "92998-3874"
│ └──── "geo"
│ ├──── "lat": "-37.3159"
│ └──── "lng": "81.1496"
├──── "phone": "1-770-736-8031 x56442"
├──── "website": "hildegard.org"
└──── "company"
├──── "name": "Romaguera-Crona"
├──── "catchPhrase": "Multi-layered client-server neural-net"
└──── "bs": "harness real-time e-markets"

これとは別ですが、もっと便利なやつで jq というものがあります。


ソースコード

https://github.com/siman-man/jt