I'm trying to perform a JSON assertion using ATLANTBH jmeter JSON PATH Assertion.
However I cant seem to write a correct expression to get the following fields from the JSON feed posted below:
- 123456789
- 1009
SOME RANDOM MESSAGE
{"api": {"status":"Success","callsremaining":36,"version":"x.x.x.x"} ,"result":{"errors":{"123456789":{"code":1009,"error":"SOME RANDOM MESSAGE"}}} }
Has anyone here got any experience using this JMeter plugin?
I know I could use regex
and Beanshell
to validate but I'd rather use these JSON Path Assertion.
Any help you could provide would be most appreciated.
Looks like you can easily assert both
1009
andSOME RANDOM MESSAGE
values using JSONPath expressions (in JSON Path Assertion components) but not sure about123456789
: that's not node value but bode name, and JSONPath implementation used by these components seems has no expressions to get node name.Suppose you can easily use to assert
123456789
instead binding of JSON Path Extractor (from the same components collection) with jmeter's standard Response_Assertion.Add 2 JSON Path Assertions as children to the sampler which returns json response you want to process:
Expressions will be
$.result.errors..code
and$.result.errors..error
correspondingly.Add JSON Path Extractor as child to the same sampler to extract full error entry:
Expression:
$.result.errors.
.This will extract
{"123456789":{"error":"SOME RANDOM MESSAGE","code":1009}}
and save into the pointed variable (${errorKey}
).Add Response Assertion as child to the same sampler, after previously added JSON Path Extractor:
This will assert name of the key (
123456789
) in the value of${errorKey}
variable.So the final construction may look like