一般 curl 後回傳的格式大概都如下
範例取自 「口罩咧?」API 使用說明
# curl https://findmasks.herokuapp.com/places/2331230018
{"type":"Feature","geometry":{"type":"Point","coordinates":[121.399996,25.147051]},"properties":{"id":"2331230018","name":"新北市八里區衛生所","phone":"(02)26102137","address":"新北市八里區舊城路16號","masksLeft":4716,"childMasksLeft":75,
為了方便查看,因此需要做格式化,網路上有許多套件可使用,以下使用 jq
工作上會用到 alpine ,用 alpine 做個範例
$ docker run -itd --name alpine-lab alpine ash
$ docker attach alpine-lab
安裝 curl jq
# apk add curl jq
Ubuntu 話
$ sudo apt install jq
加上 jq 的結果
# curl https://findmasks.herokuapp.com/places/2331230018 |jq
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
121.399996,
25.147051
]
},
"properties": {
"id": "2331230018",
"name": "新北市八里區衛生所",
"phone": "(02)26102137",
"address": "新北市八里區舊城路16號",
"masksLeft": 4716,
"childMasksLeft": 75,
"opensOn": [
"休息",
"上午、下午",
"上午、下午",
"上午",
"上午、下午",
"上午",
"休息"
],
"note": "109年民族掃墓節連續假期(4/2~4/5)休診",
"updatedAt": "2020-04-25T16:35:48.000Z"
}
}
是不是方便許多