Is it possible to save a random value from a JSON response? (Not all of them and then do a random)


I’m trying to test a webservice where the response is unpredictable. It might return 0 to 2000 items in the response.
The repsonse contains among other things an url, and I would like to pick one at random.

I know that you could save all items with jsonPath(“some json path”).findAll.optional.saveAs(“myurls”) and then use them as ${myurls.random()}.
But since my response can contain up to 2000 urls which I thought would be inefficient to save to memory. Is it possible to pick one at random right from the response without saving them all to memory first?



Will be featured in Gatling 3:
For now, only in previews available for our support subscribers.



Could transform be a temporary solution until Gatling 3?

jsonPath(“some json path”).findAll.transform(Random.shuffle(_).head).optional.saveAs(“rand_url”)

Yeah, it works.

Thank you Vu!

mandag 26. september 2016 22.36.37 UTC+2 skrev Vu Nguyen følgende: