ready-api

ReadyApi Property Transfer counting elements in JSON array response


On the Transfer Property page, how do I set a property which contains the count of the number of elements in a JSON array response?

e.g.

JSON response: [ { "category": "XXX", "other": "YYY", "another": "ZZZ" }, { "category": "XXX", "other": "YYY" , "another": "ZZZ" } ]

I am using JSON Path, and have an expression as follows: $[?(@.category == 'XXX')].length()

property -> [[3, 3]]

I require a count property to be set to 2.


Solution

  • JSONPath has very sketchy support for any functions, certainly in ReadyAPI/SoapUI.

    You could use Property: ResponseAsXml, and use the XPath count() function. So the expression will likely be count(//category='XXX')