I have a JSON which looks like:
{
"type": "server-firmwareinventory-list-1",
"members": [
{
"type": "sever-hardware-firmware-1",
"category": "sever-hardware",
"serverName": "my-host",
"components": [
{
"componentName": "firmware-hdd-8051bb7e9c",
"componentDescription": "VS000480KXALB, VS003840KWXFQ, VS001920KWXFP, and VS000960KWXFN Drives firmware",
"componentVersion": "85032G00-4.1"
},
{
"componentName": "System ROM",
"componentDescription": "SystemRomActive",
"componentVersion": "A46 v2.80 (07/31/2023)"
},
{
"componentName": "Redundant System ROM",
"componentDescription": "SystemRomBackup",
"componentVersion": "A46 v2.60 (08/11/20223)"
}
],
"serverFirmwareSettings": null
}
]
}
I can successfully get the active system ROM for each server with (${FIRMW} points to the file holding the JSON).
jq -r '.members[] | {"serverName": .serverName, "system-firmware": .components[] | select(.componentName=="System ROM") | .componentVersion }' ${FIRMW}
I wanted to add the redundant system ROM, so I tried:
jq -r '.members[] | {"serverName": .serverName, "system-firmware": .components[] | select(.componentName=="System ROM") | .componentVersion, "system-firmware-backup": | select(.componentName=="Redundant System ROM") | .componentVersion }' ${FIRMW}
but that gets me a syntax error, unexpected '|' at line 1. Any ideas how to fix this?
.members[] | .components[] | select(.componentName | contains("ROM"))but need to create my output JSON with the name and just the firmware versions.{"componentName":"System ROM","componentVersion":"A46 v2.80 (07/31/2023)"} {"componentName":"Redundant System ROM","componentVersion":"A46 v2.60 (08/11/20223)"}? If not, what?