user3834163 user3834163 - 5 months ago 77
JSON Question

Jmeter assert return results are not empty or empty

I am new to JMeter. I have an AJAX app. At some point there is a query that checking the data based on the distance criteria. If the distance is too short, the return is no results in the following JSON format:

[]
. If the distance range is big enough, the data is populated and returned as JSON Array.

I am trying to put the assertion to know when there is results or when there is no results, i.e.
[]
. How to do this?

I tried JSON Path
$[0]
and Value
[]
. I also tried Expected
null
. These doesn't work. Any help is greatly appreciated. I feel I will need to write the shell script, but feel it can be complicated.

Also our app is a bit not standard from what I saw. JSON doesn't start with
{[]}
, it starts with
[{}]
.

Answer

Testing for an empty match is fairly simple, all you need is:

  • Use a wildcard expression: $.* as JSON Path
  • Paste exact empty response into "Expected Value", any extra space or empty string will cause assertion failure.

JSON Path Assertion

See:

Comments