LoginSignup
4
1

More than 5 years have passed since last update.

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

Posted at

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

{
  "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 というものがあります。

ソースコード

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1