使用Jmeter中带有!=条件的JsonPath从JSON中提取一些值

问题描述:

我具有以下JSON,并且我需要获取没有类型= Jenkins的实例的ID值

I have the following JSON and I need to get id values for instances which do not have type = Jenkins

{
  "data": [
    {
      "id": "35002399-6fd7-40b7-b0d0-8be64e4ec09c",
      "name": "94Jenkins",
      "url": "http://127.0.0.1:8084",
      "authProvider": false,
      "siteId": "cce1b6e2-4b5d-4455-ac96-6b5d4c0d901d",
      "status": {
        "status": "ONLINE"
      },
      "instanceStateReady": true,
      "instanceState": {
        "@type": "InstanceStateDto",
        "version": "2.60.3"
      },
      "adminUser": "admin1",
      "hasDRConfig": false,
      "managed": true,
      "type": "JENKINS",
      "siteName": "City",
      "lastRefreshTime": "2018-04-24T09:43:01.694Z"
    },
    {
      "id": "5cd3caf6-bac1-4f07-8793-5f124b90eaf5",
      "name": "RJO",
      "url": "http://test.com",
      "authProvider": false,
      "status": {
        "status": "UNAUTHORIZED"
      },
      "instanceStateReady": true,
      "instanceState": {
        "@type": "numberOfArtifacts",
        "version": "5.5.2-m002",
        "licenses": {
          "RJO : artrjo-m": {
            "type": "ENTERPRISE",
            "validThrough": "Jun 12, 2021",
            "licensedTo": "Test",
            "licenseHash": "asdadsdb612bda1aae745bd2a3",
            "expired": false
          },
          "RJO : artrjo-s1": {
            "type": "ENTERPRISE",
            "validThrough": "Jun 12, 2021",
            "licensedTo": "JFrog",
            "licenseHash": "asaswca236350205a3798c0fa3",
            "expired": false
          }
        }
      },
      "adminUser": "jfmc",
      "hasDRConfig": false,
      "managed": false,
      "warnings": [
        "Site is missing",
        "Failed to connect to the service. Please verify that the service information provided is correct."
      ],
      "type": "ARTIFACTORY"
    },
    {
      "id": "0727a49a-6c95-433e-9fc5-7e5c760cc76f",
      "name": "NinetyTwo",
      "url": "http:127.0.0.1:8081",
      "authProvider": true,
      "siteId": "cce1b6e2-4b5d-4455-ac96-6b5d4c0d901d",
      "status": {
        "status": "ONLINE"
      },
      "instanceStateReady": true,
      "instanceState": {
        "@type": "numberOfArtifacts",
        "version": "5.9.0",
        "licenses": {
          "NinetyTwo": {
            "type": "ENTERPRISE",
            "validThrough": "Dec 30, 2018",
            "licensedTo": "Test",
            "licenseHash": "qweqwed95f712dbabee98184da52443",
            "expired": false
          }
        }
      },
      "adminUser": "admin",
      "hasDRConfig": false,
      "managed": true,
      "type": "ARTIFACTORY",
      "serviceId": "jfrt@01c7g4c7hq0dpd0qa71r8c09sj",
      "siteName": "Test",
      "lastRefreshTime": "2018-04-24T09:43:01.698Z"
    }
  ]
}

然后我使用$..[?(@.type!='JENKINS')].id路径接收与类型不是NOT JENKINS的实例相关的id-,但是JSON Extractor也会向我返回Jenkins的id.问题是如何仅接收非詹金斯实例的ID?

And I use $..[?(@.type!='JENKINS')].id path to receive id-s which relate to the instances with type NOT JENKINS, however JSON Extractor returns me the Jenkins's id too. The question is how can I receive ids for non-jenkins instances only?

用以下内容替换JSON路径表达式,它应该可以工作:

Replace your JSON path expression with the below and it should work:

$.data.[*][?(@.type != "JENKINS")].id