代码之家  ›  专栏  ›  技术社区  ›  Sergey Konotop

使用JsonPath和!=Jmeter中的条件

  •  3
  • Sergey Konotop  · 技术社区  · 7 年前

    我有以下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 接收与类型不是JENKINS的实例相关的id-s的路径,但是JSON提取器也会返回JENKINS的id。问题是如何仅接收非jenkins实例的ID?

    1 回复  |  直到 7 年前
        1
  •  2
  •   ararar    7 年前

    将JSON路径表达式替换为以下表达式,它应该可以工作:

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

    enter image description here