简体   繁体   中英

Select multiple JSON values from same key with jq?

I have the following JSON output:

$ system_profiler -json SPPCIDataType | jq -r '.SPPCIDataType[]'
{
  "_name": "Radeon RX 580",
  "sppci_bus": "sppci_pci_device",
  "sppci_device_type": "sppci_displaycontroller",
  "sppci_device-id": "0x67df",
  "sppci_driver_installed": "affirmative_string",
  "sppci_link-speed": "5.0 GT/s",
  "sppci_link-width": "x16",
  "sppci_msi": "Yes",
  "sppci_name": "ATY,AMD,RadeonFramebuffer",
  "sppci_revision-id": "0x00e7",
  "sppci_slot_name": "Slot-1",
  "sppci_subsystem-id": "0xe353",
  "sppci_subsystem-vendor-id": "0x1da2",
  "sppci_vendor-id": "0x1002"
}
{
  "_name": "pci1002,aaf0",
  "sppci_bus": "sppci_pci_device",
  "sppci_device_type": "sppci_audiodevice",
  "sppci_device-id": "0xaaf0",
  "sppci_driver_installed": "affirmative_string",
  "sppci_link-speed": "5.0 GT/s",
  "sppci_link-width": "x16",
  "sppci_msi": "Yes",
  "sppci_revision-id": "0x0000",
  "sppci_slot_name": "Slot-1",
  "sppci_subsystem-id": "0xaaf0",
  "sppci_subsystem-vendor-id": "0x1da2",
  "sppci_vendor-id": "0x1002"
}
{
  "_name": "PXS3",
  "sppci_bus": "sppci_pci_device",
  "sppci_device_type": "sppci_usbxhci",
  "sppci_device-id": "0x1242",
  "sppci_driver_installed": "affirmative_string",
  "sppci_link-speed": "5.0 GT/s",
  "sppci_link-width": "x2",
  "sppci_msi": "Yes",
  "sppci_revision-id": "0x0000",
  "sppci_slot_name": "Slot-3",
  "sppci_subsystem-id": "0x7230",
  "sppci_subsystem-vendor-id": "0x16b8",
  "sppci_vendor-id": "0x1b21"
}
{
  "_name": "pci144d,a808",
  "sppci_bus": "sppci_pci_device",
  "sppci_device_type": "sppci_nvme",
  "sppci_device-id": "0xa808",
  "sppci_driver_installed": "affirmative_string",
  "sppci_link-speed": "8.0 GT/s",
  "sppci_link-width": "x4",
  "sppci_msi": "Yes",
  "sppci_revision-id": "0x0000",
  "sppci_slot_name": "Slot-2@8,0,0",
  "sppci_subsystem-id": "0xa801",
  "sppci_subsystem-vendor-id": "0x144d",
  "sppci_vendor-id": "0x144d"
}
{
  "_name": "pci144d,a808",
  "sppci_bus": "sppci_pci_device",
  "sppci_device_type": "sppci_nvme",
  "sppci_device-id": "0xa808",
  "sppci_driver_installed": "affirmative_string",
  "sppci_link-speed": "8.0 GT/s",
  "sppci_link-width": "x4",
  "sppci_msi": "Yes",
  "sppci_revision-id": "0x0000",
  "sppci_slot_name": "Slot-2@9,0,0",
  "sppci_subsystem-id": "0xa801",
  "sppci_subsystem-vendor-id": "0x144d",
  "sppci_vendor-id": "0x144d"
}

I'm currently selecting the _name when sppci_device_type is equal to sppci_nvme :

$ system_profiler -json SPPCIDataType | jq -r '.SPPCIDataType[] | select(.sppci_device_type == "sppci_nvme")._name'
pci144d,a808
pci144d,a808

What is the correct select statement for a key matching any one of multiple values? Something like:

select(.sppci_device_type EQUAL TO ("sppci_audiodevice" OR "sppci_nvme"))._name
select(.sppci_device_type | . == "sppci_audiodevice" or . == "sppci_nvme") ._name

or

select(.sppci_device_type | IN("sppci_audiodevice", "sppci_nvme")) ._name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM