使用JsonPath在Jmeter中使用!= condition从JSON中提取一些值

时间:2018-04-24 12:48:15

标签: json jmeter jsonpath

我有以下JSON,我需要获取没有type = Jenkins的实例的id值

{
  "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-s,但是JSON Extractor也返回Jenkins的id。问题是我如何只收到非jenkins实例的id?

1 个答案:

答案 0 :(得分:2)

用下面的代码替换你的JSON路径表达式,它应该可以工作:

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

enter image description here