I need to have a check that validates the amount of items contained in an array from a jsonPath query to the amount expected

The response I get has a JSON body.
This JSON has several arrays contained within.
During the check of the request I need to validate the amount of elements in each such array to make sure it is as expected.

If I do the following:

.check(
status is 200,
jsonPath("$.config.userPrivileges[0]").findAll.productIterator.length == 10

)

This code is not accepted as the second line in the check returns a Boolean and not an HttpCheck object.
It is critical that if the amount of elements is not consistent with the expected, that I fail the request. As a result it is not useful for me to save the Seq to the session and process it over an additional exec.

I see there is a @.length API in jsonPath though whatever query I use I can’t seem to get that value…

Thanks in advance

Hi,

I’m not sure there is any way to handle this with jsonPath directly. Stil, there is a check DSL element called “count” that will do the trick:

jsonPath("$.config.userPrivileges[*]").count.is(10)

The “[*]” is important.

Cheers!