Is it possible to use wild cards in json validation or ignore some values in json in Jmeter

大兔子大兔子 提交于 2020-12-27 05:53:44

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/65149040/is-it-possible-to-use-wild-cards-in-json-validation-or-ignore-some-values-in-jso

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!