Reputation: 3
I have a CSV dataset config pointing to a CSV file with the following data:
Ids
87541
4551
15441
11117
.....
n
Instead of looping through the file and do multiple POST
requests for each value, I need to have a single POST
request and pass ALL the IDs the request body which should like this in the generated JSON
:
{
"ids": [
84280,
2334,
235,
32554,
3663,
346,
344643,
....,
n
]
}
Upvotes: 0
Views: 1073
Reputation: 58872
In CSV Data Set Config define delimiter which not in file as ~
Put in variable name ids
for example.
and then use it in request as { "ids": [ ${ids} ] }
Upvotes: 0
Reputation: 168157
Put the following code into "Script" area
def csvfile = new File('test.csv')
def jsonBuilder = new groovy.json.JsonBuilder()
jsonBuilder {
ids csvfile.collect { it }
}
vars.put('requestBody', jsonBuilder.toPrettyString())
log.info(vars.get('requestBody'))
The above code will read test.csv
file in JMeter's "bin" folder and create an ids
JSON Array where each element will be a line from the given file and put the result into ${requestBody}
JMeter Variable
Demo:
References:
Upvotes: 1