Ramdomize a select value

I simulate selecting a product in my application.
My get method return a json with severals product object.
I want to select id, number and version in random way for the moment I select them with an Int value = 1 which I provide every time.

.check(status.in(200 to 210))
.check(jsonPath("$[1][‘id’]").saveAs(“id”))
.check(jsonPath("$[1][‘number’]").saveAs(“number”))
.check(jsonPath("$[1][‘version’]").saveAs(“version”)))

Would you like to help me please.

First, you have to use ofMap to tell Gatling you want to extract JSON objects (Java Maps) to directly capture nodes, not fields/leaves.
Then, you have to use findRandom() to tell Gatling you want to extract one random result amongst all the matches.

.check(jsonPath("$[*]").ofMap().findRandom().saveAs("randomEntry"))

Then, later, when you have to use Gatling Expression Language to access the different fields, you’ll have to use the access by key notation.

"#{randomEntry.id}"

Thank you very much it works.