【发布时间】:2020-08-12 09:50:04
【问题描述】:
我有 json:
{
"error": 0,
"descErr": "Ok",
"seqNumber": 0,
"data": {
"events": [],
"devices": {
"aaa1234a": {
"deviceType": "aaa",
"ip": "192.168.1.4",
"otherInformation": "blabla4"
},
"aaa1235a": {
"deviceType": "aaa",
"ip": "192.168.1.5",
"otherInformation": "blabla5"
},
"aaa1236a": {
"deviceType": "aaa",
"ip": "192.168.1.6",
"otherInformation": "blabla6"
}
}
}
}
并且想要只获取设备名称(在 json 中看起来像 aaa1234a)、ip 和 otherInformation 以及 jq。
我需要一个结果:
"aaa1234a": {
"ip": "192.168.1.4",
"otherInformation": "blabla4"
},
"aaa1235a": {
"ip": "192.168.1.5",
"otherInformation": "blabla5"
},
"aaa1236a": {
"ip": "192.168.1.6",
"otherInformation": "blabla6"
}
如何用 jq 过滤这个 json,如果我不知道设备名称,但看起来像“aaa1234a”,其中 aaa - 类型设备和最后一个“a” - 型号设备 - 1234 - 动态名称
【问题讨论】:
-
jq '.data.devices'有什么问题?