aks786
aks786

Reputation: 33

Is there a way to use variable inside the index of an array in response assertion?

I have a json response. I am using json assertion where in one of the keys I have a big array. I pass Json path as $.value.page[9999].hash. Now I want to have a variable value instead of 9999. How can I use variable instead of 9999. I tried to use variable generated in beanshell post processor. But I failed. Is there any solution to this?

Upvotes: 1

Views: 388

Answers (2)

Dmitri T
Dmitri T

Reputation: 168072

You can use __V() function for this

The V (variable) function returns the result of evaluating a variable name expression. This can be used to evaluate nested variable references (which are not currently supported).

For example, if one has variables A1,A2 and N=1:

${A1} - works OK

${A${N}} - does not work (nested variable reference)

${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1

So you can come up with something like:

${__V($.value.page.[${page}].hash)}

Demo:

enter image description here

More information: Here’s What to Do to Combine Multiple JMeter Variables

Upvotes: 2

Vadim Yangunaev
Vadim Yangunaev

Reputation: 1991

Try eval() and evalVar() functions to extract what you want:

 ${__eval($.value.page[${index}].hash)}

Upvotes: 0

Related Questions