Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2020-12-04 18:44:57

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.

Questioner
Manu Chadha
Viewed
0
Dmitri T 2020-12-05 03:20:34

Since JMeter 5.2 you have JSON JMESPath Assertion which provides keys function, using it you can validate the attributes names, example configuration:

enter image description here

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