jmeter json path对等级别的条件提取

时间:2018-04-18 01:43:03

标签: jmeter jsonpath

我使用的是jmeter v2.13和jp @ gc - JSON Path Extractor。

以下是我的JSON示例:

{
  "views": [{
      "id": 9701,
      "name": " EBS: EAS: IDC (EAS MBT IDC)",
      "canEdit": true,
      "sprintSupportEnabled": true,
      "filter": {
        "id": 55464,
        "name": "Filter for EBS: EAS: IDC & oBill Boar",
        "query": "project = \"EBS: EAS: IDC\"",
        "owner": {},
        "canEdit": false,
        "isOrderedByRank": true,
        "permissionEntries": [{
          "values": [{
            "type": "Shared with the public",
            "name": ""
          }]
        }]
      },
      "boardAdmins": {}
    },
    {}
  ]
}

是否可以提取views[x].id,其中存在等于views[x].filter.permissionEntries[*].values[*].type的条目Shared with the public

我该怎么做?

由于

1 个答案:

答案 0 :(得分:0)

JSON Query看起来像这样(我承认我没有在JMeter中尝试)

$.views[?(@.filter[?(@.permissionEntries[?(@.values[?(@.type == "Shared with the public")])])])].id

说明:

我们希望在根($)下有views,并且它具有属性id。其余(在[]中)是根据预定义条件仅选择views项的条件。因此 $。views [conditions] .id

这种情况下的条件是另一种情况,但主要部分是:

  • 我们将条件定义为过滤器?(...)

  • 我们要求过滤器在当前项目(@)下查找特定子项目(.child),子项可能有自己的条件([...])。因此 @。child [conditions] 。这样我们就可以浏览filterpermissionEntriesvalues

  • 最后,我们转到values字段并对具有特定值type的子Shared with the public字段进行过滤。因此 @。type ==“与公众共享”

如你所见,它不是很直观,而且JSON路径有点受限。如果这是一个重复的问题,并且您的JSON更加复杂,那么您可以考虑投资可编写脚本的预处理器(类似于解释here的那个。