Help referring to variables randomly

Hi

I’d like to randomly refer to a string variable that I’m getting from a .json file, but I’m not sure how to implement it. The solutions I’ve seen are all for xml files.
This is the structure of the json file:

{ "1": "rabbit", "2": "rat", "3": "cat", "4": "mat", "total": "4" }

At the beginning of the scene: Send request to “”“new.json” with body: “” (to variable response)
Parse JSON string VariableString(response) and store it into variable jason
Do = VariableString(jason.4) to the text of ies

I would like to put a random text (something like jason.Random()) into the the text of ies.

I’m using JSON because I would like to put this online and the xml didn’t seem to work at all. I also tried to set up the json file as an array, but couldn’t get that to work either.

Please help.

Instead the “static” notation:

json.4

use the “dynamic” notation:

json["4"]

The expression between the “[]” is a string, so you can convert a random number into a string, and put the random string inside the brackets:

Do = VariableString(  json[ ToString(Random(3) + 1) ]  ) to the text of ies

Random(3) returns a random number between 0 and 3, so Random(3) + 1 returns a random number between 1 and 4 :wink:

Thanks so much Lizard! I was struggling with that for hours. By the way the line of code should be:

Do = VariableString(jason[ToString(Random(3) + 1)]) to the text of ies

All the best with your studies.

Yeah, thanks, I will fix that :stuck_out_tongue: … I had written it ok wo lines before (facepalm)