简体   繁体   中英

Gatling : Update content of JSON file before using it as request body

{
  "aggregateResults": true,
  "targetTimeSeries": "finalForecast",
  "filter": {
    "id": "f3456789sdsd779sds4488"
  }
}

This the content of my JSON file, I want to change the value of id before sending this JSON as body in a POST request for my gatling script.

Since this is small JSON, currently I am passing it to StringBody and replacing the dynamic part to achieve this successfully but this method will not be useful for long JSON responses with which I have to deal with in future.

Please guide.

You can embed gatling expressions in your JSON.

Assuming your desired id is in a session variable called "id" you could have your file like this:

{
  "aggregateResults": true,
  "targetTimeSeries": "finalForecast",
  "filter": {
    "id": "${id}"
  }
}

And then use an ELFileBody instead of a RawFileBody to supply the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM