0

In one of my GET requests, I store the JSON response into an Environmental Variable Array. I cannot seem to access the individual values in that array. Is this supported or am I just not accessing them properly?

My Environment Array

[Environment Variables Tab]

Variable Name    |    Value
-----------------------------------  
myJsonArray      |   ["value1","value2","value3"]

Using entire Array

This picture just shows that Thunder client recognizes the variable myJsonArray as it's text is green.
{{baseURL}}route/{{myJsonArray}}

Trying to access individual values in array

This picture shows that Thunder client does NOT recognize the attempt to access array element 2 via myJsonArray[2], as it's text is grey.
{{baseURL}}route/{{myJsonArray[2]}}

Result of trying with square brackets

This picture shows the console output when trying to use the above array element.
Request Url: https://10.20.30.40/sidecar/route/%7B%7BmyJsonArray[2]%7D%7D

I also tried myArray.[2].

1 Answers1

0

It seems that Thunder Client does not handle arrays natively. I have a similar problem using tc.getVar() to retrieve a boolean value. It turns out I need to make boolean conversion manually, something like var myVar = tc.getVar("var_name") === "true".

For your use case, the simplest method I could think of is to store the actual array element needed in a separate var. (I do not understand why you put the entire array into URL. But for accessing individual values in array, this method should work.)

Otherwise, you may leverage JSON.parse() to parse the array from a string with custom filters.

Ref: https://github.com/rangav/thunder-client-support/blob/master/docs/filters.md

George
  • 91
  • 1
  • 3