Jmeter Json Extractor多种条件

时间:2018-04-12 04:41:22

标签: json jmeter

我想提取id的值,其中Principals.value.type ='USER',但我的json有多个'id'标签。我希望提取第一个。 注意:响应中可以有多个jsons

示例json:
{"content":[{"id":"210A3A-0135-1036-90B8-0A2163","name":"xyy 927","description":"xyz Description","policy_set":"xyz2","offline_lease_period":{"value":102,"constraint":"NOT_CHANGEABLE"},"is_tracked":{"value":true,"constraint":"NOT_CHANGEABLE"},"validity_period":{"value":{"days":195,"type":"Relative"},"constraint":"NOT_CHANGEABLE"},"principals":{"value":[{"common_name":"xyz@gmail.com","id":"8B5F4-96C2-1035-8AB7-0A2163","domain":"APRM Domain","role":"DEFAULT","email":"abc@gmail.com","updated":"2017-11-02T04:54:49.272Z","created":"2017-11-02T04:54:49.272Z","type":"USER"}],"constraint":"NOT_CHANGEABLE"},"permissions":{"value":[],"constraint":"NOT_CHANGEABLE"},"watermark_id":{"value":"","constraint":"NOT_CHANGEABLE"},"policy_type":"NON_CUSTOMIZABLE","created":"2018-03-09T04:41:31.277Z","updated":"2018-03-09T04:41:31.386Z"}

2 个答案:

答案 0 :(得分:0)

首先你的json返回错误

 Parse error on line 1:
...3-09T04:41:31.386Z"}
-----------------------^
Expecting ',', ']', got 'EOF'

如果您能够使用Json Extractor获取Id标记然后您可以使用变量名称_Count,例如Image shows extracting Device ID 1

答案 1 :(得分:0)

相关的JSON Path查询类似于:

$..principals.value[?(@.type == 'USER')].id

JMeter JSON Path Extractor

如果您想要第一个ID,您可以设置"匹配否#34;到JSON Extractor

中的1

参考文献: