我有一个以这种方式开头的JSON(我已经编辑了文件的末尾以关闭左括号以使其成为有效文件):
{
"YRPLBn9VEgpB4pc": {
"name": "Bright",
"lights": [
"8"
],
"owner": "VHB3Xij-S9AfghoMDL6ccgCEOOE00Fs43nzBbNgR",
"recycle": false,
"locked": false,
"appdata": {
"version": 1,
"data": "7prbY_r03_d05"
},
"picture": "",
"lastupdated": "2018-07-24T12:51:03",
"version": 2
},
"oRvYDYW6dMmGoUw": {
"name": "Dimmed",
"lights": [
"8"
],
"owner": "VHB3Xij-S9AfghoMDL6ccgCEOOE00Fs43nzBbNgR",
"recycle": false,
"locked": false,
"appdata": {
"version": 1,
"data": "jBjTp_r03_d06"
},
"picture": "",
"lastupdated": "2018-07-24T12:51:03",
"version": 2
}
}
Philips Hue Clip api返回它,以响应询问桥上保存的所有场景的查询。
我想对此进行迭代(最好使用bash,但我愿意接受建议),以便可以获取项目“ YRPLBn9VEgpB4pc”,“ oRvYDYW6dMmGoUw”等。我知道如何从密钥对中获取值*,但我不太了解这些项目是什么-也许是对象ID?
*使用jq从“名称”中获取值:
for row in $(echo "${sample}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1};
};
echo $(_jq '.name');
done