Adding a saved list to the next request body

Hi
I have a request that returns a body out of which I extract a list from the jason response like so:

.check(jsonPath("$.data[*].drugName").findAll().saveAs("topResults"))

This sets topResults to a string value of an array of drugnames
I’d like to use this array in another request body. I tried using elfilebody with:

"topResults": ["${topResults}"]

but that does not set it as an array of all the elements. It sets it as a single element array with a string of all the elements. I also tried splitting the string and adding it as an array using:

"topResults": "${topResults}"

but that, again adds a string and not an array
How to I add an extracted json array to the body of another request?
A

jsonStringify()

1 Like

jsonStringlify still turns it into a string. Using

"topResults": "#{topResults.jsonStringify()}"

in the json creates a json with

.body(ElFileBody("requestBodies/allFilters.json"))

of

 "topResults": "["drug1","drug2","drug3","drug4","drug5","drug6","drug7","drug8"]"

which is a string instead of

"topResults": ["drug1","drug2","drug3","drug4","drug5","drug6","drug7","drug8"]

which is a json array

Your template is the one that adds the extra quotes.

try with:

"topResults": #{topResults.jsonStringify()}

Cheers!

that worked but idea underlines it as invalid json format. I had to disable inspection. Thanks for your help