jq: select 如果字段 n 是 x,则只有必要的字段

jq: select only necessary fields if the field n is x

我有以下JSON方案:

{
  "CVE_data_type" : "CVE",
  "CVE_data_format" : "MITRE",
  "CVE_data_version" : "4.0",
  "CVE_data_numberOfCVEs" : "19162",
  "CVE_data_timestamp" : "2022-02-24T08:00Z",
  "CVE_Items" : [ {
    "cve" : {
      "data_type" : "CVE",
      "data_format" : "MITRE",
      "data_version" : "4.0",
      "CVE_data_meta" : {
        "ID" : "CVE-2020-0597",
        "ASSIGNER" : "secure@intel.com"
      },
      "problemtype" : {
        "problemtype_data" : [ {
          "description" : [ {
            "lang" : "en",
            "value" : "CWE-125"
          } ]
        } ]
      },
      "references" : {
        "reference_data" : [ {
          "url" : "https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00295.html",
          "name" : "https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00295.html",
          "refsource" : "MISC",
          "tags" : [ "Vendor Advisory" ]
        }, {
          "url" : "https://www.synology.com/security/advisory/Synology_SA_20_15",
          "name" : "https://www.synology.com/security/advisory/Synology_SA_20_15",
          "refsource" : "CONFIRM",
          "tags" : [ "Third Party Advisory" ]
        }, {
          "url" : "https://support.lenovo.com/de/en/product_security/len-30041",
          "name" : "https://support.lenovo.com/de/en/product_security/len-30041",
          "refsource" : "MISC",
          "tags" : [ ]
        }, {
          "url" : "https://security.netapp.com/advisory/ntap-20200611-0007/",
          "name" : "https://security.netapp.com/advisory/ntap-20200611-0007/",
          "refsource" : "CONFIRM",
          "tags" : [ ]
        }, {
          "url" : "https://www.kb.cert.org/vuls/id/257161",
          "name" : "VU#257161",
          "refsource" : "CERT-VN",
          "tags" : [ ]
        } ]
      },
      "description" : {
        "description_data" : [ {
          "lang" : "en",
          "value" : "Out-of-bounds read in IPv6 subsystem in Intel(R) AMT and Intel(R) ISM versions before 14.0.33 may allow an unauthenticated user to potentially enable denial of service via network access."
        } ]
      }
    },
    "configurations" : {
      "CVE_data_version" : "4.0",
      "nodes" : [ {
        "operator" : "OR",
        "children" : [ ],
        "cpe_match" : [ {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "11.0",
          "versionEndIncluding" : "11.8.76",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "11.10",
          "versionEndIncluding" : "11.11.76",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "11.20",
          "versionEndIncluding" : "11.22.76",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "12.0",
          "versionEndIncluding" : "12.0.63",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "13.0",
          "versionEndIncluding" : "13.0.31",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:active_management_technology:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "14.0",
          "versionEndIncluding" : "14.0.32",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "11.0",
          "versionEndIncluding" : "11.8.76",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "11.10",
          "versionEndIncluding" : "11.11.76",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "11.20",
          "versionEndIncluding" : "11.22.76",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "12.0",
          "versionEndIncluding" : "12.0.63",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "13.0",
          "versionEndIncluding" : "13.0.31",
          "cpe_name" : [ ]
        }, {
          "vulnerable" : true,
          "cpe23Uri" : "cpe:2.3:a:intel:software_manager:*:*:*:*:*:*:*:*",
          "versionStartIncluding" : "14.0",
          "versionEndIncluding" : "14.0.32",
          "cpe_name" : [ ]
        } ]
      } ]
    },
    "impact" : {
      "baseMetricV3" : {
        "cvssV3" : {
          "version" : "3.1",
          "vectorString" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
          "attackVector" : "NETWORK",
          "attackComplexity" : "LOW",
          "privilegesRequired" : "NONE",
          "userInteraction" : "NONE",
          "scope" : "UNCHANGED",
          "confidentialityImpact" : "NONE",
          "integrityImpact" : "NONE",
          "availabilityImpact" : "HIGH",
          "baseScore" : 7.5,
          "baseSeverity" : "HIGH"
        },
        "exploitabilityScore" : 3.9,
        "impactScore" : 3.6
      },
      "baseMetricV2" : {
        "cvssV2" : {
          "version" : "2.0",
          "vectorString" : "AV:N/AC:L/Au:N/C:N/I:N/A:P",
          "accessVector" : "NETWORK",
          "accessComplexity" : "LOW",
          "authentication" : "NONE",
          "confidentialityImpact" : "NONE",
          "integrityImpact" : "NONE",
          "availabilityImpact" : "PARTIAL",
          "baseScore" : 5.0
        },
        "severity" : "MEDIUM",
        "exploitabilityScore" : 10.0,
        "impactScore" : 2.9,
        "acInsufInfo" : false,
        "obtainAllPrivilege" : false,
        "obtainUserPrivilege" : false,
        "obtainOtherPrivilege" : false,
        "userInteractionRequired" : false
      }
    },
    "publishedDate" : "2020-06-15T14:15Z",
    "lastModifiedDate" : "2021-03-18T13:15Z"
 }, {
    "cve" : {[...]

如果 ID 值为 CVE-2020-0597,我需要从架构中获取以下值:

CWE-125

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

7.5

我从来没有用过这个,所以我有点难以理解如何在这个结构中做到这一点。有人可以给我举个例子吗?

没有关于条件、数组索引等的更多详细信息,我想这就是您想要的:

jq -r '
  .CVE_Items[] | select(.cve.CVE_data_meta.ID == "CVE-2020-0597")
  | .cve.problemtype.problemtype_data[0].description[0].value, 
    (.impact.baseMetricV3.cvssV3 | .vectorString, .baseScore)
'
CWE-125
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
7.5

Demo