【发布时间】:2021-12-29 18:25:23
【问题描述】:
这是我从我的 api 中提取的原始数据:
{
"observations": [
{
"winddir": 292,
"humidity": 92,
"qcStatus": 1,
"imperial": {
"temp": 20,
"heatIndex": 20,
"dewpt": 40,
"windChill": 20,
"windSpeed": 3,
"windGust": 3,
"pressure": 29.71,
"precipRate": 0,
"precipTotal": 0.01,
"elev": 1905
}
}
]
}
这是我运行的命令:
curl -s 'https://api.myawesomeapidata.com' | jq -r '.observations[].winddir, .observations[].humidity, .observations[].imperial.temp'
这是输出:
292
92
20
这是我想要的输出:
Wind Direction: 292
Humidity: 92
Temperature: 20
但如果这是输出就好了:
winddir: 292
humidity: 92
temp: 20
如您所见,我希望键出现在值的前面。最好允许我在打印之前更改键名(风向),但我也可以使用原始键名(winddir)。
【问题讨论】: