やりたいこと
- ターミナルでJSONを見やすく表示させたい
- 一行で返ってくるので見づらい
$ curl https://query.yahooapis.com/v1/public/yql\?q\=select%20\*%20from%20weather.forecast%20where%20woeid%20in%20\(select%20woeid%20from%20geo.places\(1\)%20where%20text%3D%22nome%2C%20ak%22\)\&format\=json\&env\=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
{"query":{"count":1,"created":"2018-03-06T08:10:55Z","lang":"en-US","results":{"channel":{"units":{"distance":"mi","pressure":"in","speed":"mph","temperature":"F"},"title":"Yahoo! Weather - Nome, AK, US","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/","description":"Yahoo! Weather for Nome, AK, US","language":"en-us","lastBuildDate":"Mon, 05 Mar 2018 11:10 PM AKST","ttl":"60","location":{"city":"Nome","country":"United States","region":" AK"},"wind":{"chill":"19","direction":"158","speed":"14"},"atmosphere":{"humidity":"95","pressure":"1015.0","rising":"0","visibility":"9.4"},"astronomy":{"sunrise":"8:56 am","sunset":"7:32 pm"},"image":{"title":"Yahoo! Weather","width":"142","height":"18","link":"http://weather.yahoo.com","url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"},"item":{"title":"Conditions for Nome, AK, US at 10:00 PM AKST","lat":"64.499474","long":"-165.405792","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/","pubDate":"Mon, 05 Mar 2018 10:00 PM AKST","condition":{"code":"26","date":"Mon, 05 Mar 2018 10:00 PM AKST","temp":"29","text":"Cloudy"},"forecast":[{"code":"26","date":"05 Mar 2018","day":"Mon","high":"30","low":"27","text":"Cloudy"},{"code":"26","date":"06 Mar 2018","day":"Tue","high":"29","low":"27","text":"Cloudy"},{"code":"14","date":"07 Mar 2018","day":"Wed","high":"28","low":"24","text":"Snow Showers"},{"code":"26","date":"08 Mar 2018","day":"Thu","high":"25","low":"18","text":"Cloudy"},{"code":"28","date":"09 Mar 2018","day":"Fri","high":"17","low":"8","text":"Mostly Cloudy"},{"code":"30","date":"10 Mar 2018","day":"Sat","high":"8","low":"0","text":"Partly Cloudy"},{"code":"30","date":"11 Mar 2018","day":"Sun","high":"12","low":"4","text":"Partly Cloudy"},{"code":"34","date":"12 Mar 2018","day":"Mon","high":"9","low":"1","text":"Mostly Sunny"},{"code":"32","date":"13 Mar 2018","day":"Tue","high":"1","low":"-5","text":"Sunny"},{"code":"30","date":"14 Mar 2018","day":"Wed","high":"2","low":"-8","text":"Partly Cloudy"}],"description":"<![CDATA[<img src=\"http://l.yimg.com/a/i/us/we/52/26.gif\"/>\n<BR />\n<b>Current Conditions:</b>\n<BR />Cloudy\n<BR />\n<BR />\n<b>Forecast:</b>\n<BR /> Mon - Cloudy. High: 30Low: 27\n<BR /> Tue - Cloudy. High: 29Low: 27\n<BR /> Wed - Snow Showers. High: 28Low: 24\n<BR /> Thu - Cloudy. High: 25Low: 18\n<BR /> Fri - Mostly Cloudy. High: 17Low: 8\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/\">Full Forecast at Yahoo! Weather</a>\n<BR />\n<BR />\n<BR />\n]]>","guid":{"isPermaLink":"false"}}}}}}%
準備
インストール
- Homebrewで
jq
をインストール
$ brew install jq
使い方
- パイプラインで
jq
をつけるだけ
$ curl https://query.yahooapis.com/v1/public/yql\?q\=select%20\*%20from%20weather.forecast%20where%20woeid%20in%20\(select%20woeid%20from%20geo.places\(1\)%20where%20text%3D%22nome%2C%20ak%22\)\&format\=json\&env\=store%3A%2F%2Fdatatables.org%2Falltableswithkeys | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2757 0 2757 0 0 5091 0 --:--:-- --:--:-- --:--:-- 5086
{
"query": {
"count": 1,
"created": "2018-03-06T08:13:32Z",
"lang": "en-US",
"results": {
"channel": {
"units": {
"distance": "mi",
"pressure": "in",
"speed": "mph",
"temperature": "F"
},
"title": "Yahoo! Weather - Nome, AK, US",
"link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/",
"description": "Yahoo! Weather for Nome, AK, US",
"language": "en-us",
"lastBuildDate": "Mon, 05 Mar 2018 11:13 PM AKST",
"ttl": "60",
"location": {
"city": "Nome",
"country": "United States",
"region": " AK"
},
"wind": {
"chill": "19",
"direction": "158",
"speed": "14"
},
"atmosphere": {
"humidity": "95",
"pressure": "1015.0",
"rising": "0",
"visibility": "9.4"
},
"astronomy": {
"sunrise": "8:56 am",
"sunset": "7:32 pm"
},
"image": {
"title": "Yahoo! Weather",
"width": "142",
"height": "18",
"link": "http://weather.yahoo.com",
"url": "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"
},
"item": {
"title": "Conditions for Nome, AK, US at 10:00 PM AKST",
"lat": "64.499474",
"long": "-165.405792",
"link": "http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/",
"pubDate": "Mon, 05 Mar 2018 10:00 PM AKST",
"condition": {
"code": "26",
"date": "Mon, 05 Mar 2018 10:00 PM AKST",
"temp": "29",
"text": "Cloudy"
},
"forecast": [
{
"code": "26",
"date": "05 Mar 2018",
"day": "Mon",
"high": "30",
"low": "27",
"text": "Cloudy"
},
{
"code": "26",
"date": "06 Mar 2018",
"day": "Tue",
"high": "29",
"low": "27",
"text": "Cloudy"
},
{
"code": "14",
"date": "07 Mar 2018",
"day": "Wed",
"high": "28",
"low": "24",
"text": "Snow Showers"
},
{
"code": "26",
"date": "08 Mar 2018",
"day": "Thu",
"high": "25",
"low": "18",
"text": "Cloudy"
},
{
"code": "28",
"date": "09 Mar 2018",
"day": "Fri",
"high": "17",
"low": "8",
"text": "Mostly Cloudy"
},
{
"code": "30",
"date": "10 Mar 2018",
"day": "Sat",
"high": "8",
"low": "0",
"text": "Partly Cloudy"
},
{
"code": "30",
"date": "11 Mar 2018",
"day": "Sun",
"high": "12",
"low": "4",
"text": "Partly Cloudy"
},
{
"code": "34",
"date": "12 Mar 2018",
"day": "Mon",
"high": "9",
"low": "1",
"text": "Mostly Sunny"
},
{
"code": "32",
"date": "13 Mar 2018",
"day": "Tue",
"high": "1",
"low": "-5",
"text": "Sunny"
},
{
"code": "30",
"date": "14 Mar 2018",
"day": "Wed",
"high": "2",
"low": "-8",
"text": "Partly Cloudy"
}
],
"description": "<![CDATA[<img src=\"http://l.yimg.com/a/i/us/we/52/26.gif\"/>\n<BR />\n<b>Current Conditions:</b>\n<BR />Cloudy\n<BR />\n<BR />\n<b>Forecast:</b>\n<BR /> Mon - Cloudy. High: 30Low: 27\n<BR /> Tue - Cloudy. High: 29Low: 27\n<BR /> Wed - Snow Showers. High: 28Low: 24\n<BR /> Thu - Cloudy. High: 25Low: 18\n<BR /> Fri - Mostly Cloudy. High: 17Low: 8\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2460286/\">Full Forecast at Yahoo! Weather</a>\n<BR />\n<BR />\n<BR />\n]]>",
"guid": {
"isPermaLink": "false"
}
}
}
}
}
}