我有一个 JSON,想使用 https://github.com/thedevsaddam/gojsonq
解析嵌套数组{
"total": 2,
"page": 1,
"pageSize": 50,
"data": [
{
"id": "vm-12345",
"host_id":"host-12345",
"name": "MyVirtualMachine",
"guestOS": "Windows Server 2019",
"powerState": "poweredOn",
"cpu": 2,
"memoryMB": 4096,
"disks": [
{
"id": "disk-56789",
"name": "Hard disk 1",
"capacityGB": 100,
"type": "thin"
}
],
"networks": [
{
"id": "network-98765",
"name": "VM Network",
"macAddress": "00:50:56:9A:76:5C",
"ipAddress": "192.168.1.100"
}
],
"toolsRunningStatus": "guestToolsRunning",
"connectionState": "connected"
},
{
"id": "vm-67890",
"host_id":"host-67890",
"name": "TestVM",
"guestOS": "Ubuntu 20.04",
"powerState": "poweredOff",
"cpu": 1,
"memoryMB": 2048,
"disks": [
{
"id": "disk-12345",
"name": "Hard disk 1",
"capacityGB": 50,
"type": "thick"
}
],
"networks": [
{
"id": "network-54321",
"name": "VM Network",
"macAddress": "00:50:56:9A:12:34",
"ipAddress": "192.168.1.101"
}
],
"toolsRunningStatus": "guestToolsNotRunning",
"connectionState": "disconnected"
}
]
}
正如我们在这里看到的,我们在
disks
下有 data
,我正在使用这个
jq_vm.From("data").Select("id", "name", "host_id", "disks.capacityGB").Get()
过滤掉,但这不会返回磁盘,可以在此处看到
[map[host_id:host-12345 id:vm-12345 name:MyVirtualMachine] map[host_id:host-67890 id:vm-67890 name:TestVM]]
谁能帮我解决这个问题吗?