Issue
I am sending json files as body. There are like 10k json files so I am using Directory Listing Config in jmeter plugin. While reading the json file I am using this:
${__FileToString(${file},,)}
to read file information. Json file looks like this:
{
"type": "transaction",
"entry": [
{
"fullUrl": "urn:oaeignaeogin",
"resource": {
"resourceType": "Player",
"id": "aegaegaeg-aega-aegg-aegeag-aegaegeag",
"text": {
"status": "generated",
"div": "<div xmlns=\"stuff"
},
"multipleBirthBoolean": false,
"communication": [
{
"language": {
"coding": [
{
"system": "urn:437",
"code": "en-US",
"display": "English"
}
],
"text": "English"
}
}
]
},
"request": {
"method": "POST",
"url": "Patient"
}
}
]
}
What do I do so that I only read entries upto 25 entries and then send it as body? Any help is appreciated.
Solution
Your JSON file contains only one entry
element
If there are files with more than one entry
and you need to send only first 25 you will need to parse the JSON using JSR223 PreProcessor, extract first 25 entries, re-build the JSON and overwrite the variable.
Add JSR223 PreProcessor as a child of the request which you need to send
Put the following code into "Script" area:
def json = new groovy.json.JsonSlurper().parse(new File(vars.get('file'))) if (json.entry.size() > 25) { json.entry = json.entry.take(25) } vars.put('payload', new groovy.json.JsonBuilder(json).toPrettyString())
Replace
${__FileToString(${file},,)}
in the "Body Data" tab of the "HTTP Request" Sampler
More information:
Answered By - Dmitri T
Answer Checked By - Mildred Charles (JavaFixing Admin)