我使用的是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
?
我该怎么做?
由于
答案 0 :(得分:0)
JSON Query看起来像这样(我承认我没有在JMeter中尝试)
$.views[?(@.filter[?(@.permissionEntries[?(@.values[?(@.type == "Shared with the public")])])])].id
说明:
我们希望在根($
)下有views
,并且它具有属性id
。其余(在[]
中)是根据预定义条件仅选择views
项的条件。因此 $。views [conditions] .id
这种情况下的条件是另一种情况,但主要部分是:
我们将条件定义为过滤器?(...)
我们要求过滤器在当前项目(@
)下查找特定子项目(.child
),子项可能有自己的条件([...]
)。因此 @。child [conditions] 。这样我们就可以浏览filter
,permissionEntries
,values
最后,我们转到values
字段并对具有特定值type
的子Shared with the public
字段进行过滤。因此 @。type ==“与公众共享”
如你所见,它不是很直观,而且JSON路径有点受限。如果这是一个重复的问题,并且您的JSON更加复杂,那么您可以考虑投资可编写脚本的预处理器(类似于解释here的那个。