ATLANTBH jmeter-components: JSON Path Assertion
Asked Answered
D

1

7

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:

  1. 123456789
  2. 1009
  3. 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.

Doubling answered 25/10, 2012 at 15:54 Comment(0)
L
3

Looks like you can easily assert both 1009 and SOME RANDOM MESSAGE values using JSONPath expressions (in JSON Path Assertion components) but not sure about 123456789: 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.

  1. Add 2 JSON Path Assertions as children to the sampler which returns json response you want to process:

    enter image description here

    enter image description here

    Expressions will be $.result.errors..code and $.result.errors..error correspondingly.

  2. Add JSON Path Extractor as child to the same sampler to extract full error entry:

    enter image description here

    Expression: $.result.errors..
    This will extract {"123456789":{"error":"SOME RANDOM MESSAGE","code":1009}} and save into the pointed variable (${errorKey}).

  3. Add Response Assertion as child to the same sampler, after previously added JSON Path Extractor:

    enter image description here

    This will assert name of the key (123456789) in the value of ${errorKey} variable.


So the final construction may look like

...
YOUR Sampler
    JSON Path Extractor
    JSON Path Assertion
    JSON Path Assertion
    Response Assertion
...
Liquefy answered 22/2, 2013 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.