是否可以在 json 验证中使用通配符或在 Jmeter 中忽略 json 中的某些值 [英] Is it possible to use wild cards in json validation or ignore some values in json in Jmeter
问题描述
我的 jmeter
应用程序发送一个请求并期望响应中包含以下 json
.
{"external-profile":{"email":"myemail@gmail.com","firstname":"fn","lastname":"ln",";投资组合":{field1":[],field2":[],field3":[]}}}
field1
、field2
和 field3
可以是空数组或可能有一些值.有没有办法检查消息是否有 field1,2,3
但忽略该值?
我尝试这样做,但它不起作用 - {external-profile":{email":myemail@gmail.com",firstname":fn",姓氏":ln",投资组合":{field1":[.*],field2":[.*],field3":[.*]}}}
.老实说,我不知道这是不是在jmeter
中指定正则表达式的正确方式.
自从
以及便于复制和粘贴的文本表示:
- JMESPath:
join(',',keys(external-profile".portfolio))
- 预期值:
field1,field2,field3
但是,如果字段"的顺序不正确,则会失败.会有所不同,因此您可能想要使用 JSON Schema Validator 代替,它可以是来自 JSR223 断言
My jmeter
application sends a request and expects the following json
in the response.
{"external-profile":{"email":"myemail@gmail.com","firstname":"fn","lastname":"ln","portfolio":{"field1":[],"field2":[],"field3":[]}}}
field1
, field2
and field3
could be empty arrays or might have some value. Is there a way to check that the message has field1,2,3
but ignore the value?
I tried doing this but it doesn't work - {"external-profile":{"email":"myemail@gmail.com","firstname":"fn","lastname":"ln","portfolio":{"field1":[.*],"field2":[.*],"field3":[.*]}}}
. To be honest, I don't know if this is the right way to specify regular expressions in jmeter
.
Since JMeter 5.2 you have JSON JMESPath Assertion which provides keys
function, using it you can validate the attributes names, example configuration:
And textual representations for easier copying and pasting:
- JMESPath:
join(',',keys("external-profile".portfolio))
- Expected value:
field1,field2,field3
However it will fail if the order of "fields" will be different so you might want to go for JSON Schema Validator instead, it can be used from JSR223 Assertion
这篇关于是否可以在 json 验证中使用通配符或在 Jmeter 中忽略 json 中的某些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!