Linux版はもちろん、Windows版もあり重宝する。CentOSをベースに備忘録で記載しておく。
# モジュールを入手 $ wget http://stedolan.github.io/jq/download/linux64/jq $ chmod a+x jq $ sudo mv jq /usr/local/bin $ jq jq - commandline JSON processor [version 1.4] Usage: ./jq [options][file...] For a description of the command line options and how to write jq filters (and why you might want to) see the jq manpage, or the online documentation at http://stedolan.github.com/jq
次に使い方。たとえば路線/駅名データ等の地理情報をAPIで提供してれるHeartRails Expressというサービスがあるので、そこから皇居付近の駅を検索し、得られたjsonデータを見てみる。 ※緯度・経度はGoogleマップで検索
# まずはjqなしで見てみる。
$ curl "http://express.heartrails.com/api/json?method=getStations&x=139.752249&y=35.683782"
{"response":{"station":[{"x":139.751813,"next":"有楽町","prev":"永田町","distance":"710m","y":35.677443,"line":"東京メトロ有楽町線","postal":"1000013","name":"桜田門","prefecture":"東京都"},{"x":139.757667,"next":"大手町","prev":"九段下","distance":"890m","y":35.690442,"line":"東京メトロ東西線","postal":"1000003","name":"竹橋","prefecture":"東京都"},{"x":139.76178,"next":"日比谷","prev":"大手町","distance":"940m","y":35.6805,"line":"東京メトロ千代田線","postal":"1000005","name":"二重橋前","prefecture":"東京都"}]}}
|jq ".response"
# 何ともみづらいので、整形。
$ curl "http://express.heartrails.com/api/json?method=getStations&x=139.752249&y=35.683782" | jq "."
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
116 582 116 582 0 0 112 0 0:00:05 0:00:05 --:--:-- 9238
{
"response": {
"station": [
{
"x": 139.751813,
"next": "有楽町",
"prev": "永田町",
"distance": "710m",
"y": 35.677443,
"line": "東京メトロ有楽町線",
"postal": "1000013",
"name": "桜田門",
"prefecture": "東京都"
},
{
"x": 139.757667,
"next": "大手町",
"prev": "九段下",
"distance": "890m",
"y": 35.690442,
"line": "東京メトロ東西線",
"postal": "1000003",
"name": "竹橋",
"prefecture": "東京都"
},
{
"x": 139.76178,
"next": "日比谷",
"prev": "大手町",
"distance": "940m",
"y": 35.6805,
"line": "東京メトロ千代田線",
"postal": "1000005",
"name": "二重橋前",
"prefecture": "東京都"
}
]
}
}
見やすくなりましたね。いろいろとフィルタや関数機能もあるみたいなので、触ってみると面白そうです。
0 件のコメント:
コメントを投稿