是否可以在json验证中使用通配符或忽略Jmeter中json中的某些值 [英] Is it possible to use wild cards in json validation or ignore some values in json in Jmeter

查看:83
本文介绍了是否可以在json验证中使用通配符或忽略Jmeter中json中的某些值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jmeter应用程序发送一个请求,并期望响应中出现以下json.

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":[]}}}

field1field2field3可以为空数组或可能具有某些值.有没有办法检查邮件是否包含field1,2,3但忽略该值?

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?

我尝试这样做,但是不起作用-{"external-profile":{"email":"myemail@gmail.com","firstname":"fn","lastname":"ln","portfolio":{"field1":[\.*],"field2":[\.*],"field3":[\.*]}}}.老实说,我不知道这是否是在jmeter中指定正则表达式的正确方法.

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.

推荐答案

由于 JMeter 5.2 ,您有 JSON JMESPath断言提供了

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))
  • 期望值:field1,field2,field3
  • JMESPath: join(',',keys("external-profile".portfolio))
  • Expected value: field1,field2,field3

但是,如果按"fields"的顺序,则它将失败.会有所不同,因此您可能想使用 JSON模式验证器,在 JSR223声明

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆