0

https://stackoverflow.com/a/27637247/12820240

I saw above answer (https://stackoverflow.com/a/27637247/12820240) from another question, but my questions is, Is there anyway that that I can build large Json Request by adding comma separated with new data? Would appreciate for any help/direction. for ex:

{
{
  "phoneNo": "9998885551",
  "lastName": "john25",
  "email": "[email protected]",
  "firstName": "ricky25",
  "mobileNo": "9820420420"
},
{
  "phoneNo": "9998885552",
  "lastName": "john26",
  "email": "[email protected]",
  "firstName": "ricky25",
  "mobileNo": "9820420421"
},
{
  "phoneNo": "9998885553",
  "lastName": "john27",
  "email": "[email protected]",
  "firstName": "ricky27",
  "mobileNo": "9820420422"
}

...

}

Thank you

1 Answer 1

0

Given your CSV file looks like:

9998885551,john25,[email protected],ricky25,9820420420
9998885552,john26,[email protected],ricky26,9820420421
  1. Add JSR223 PreProcessor as a child of the HTTP Request sampler which body you want to generate
  2. Put the following code into "Script" area:

    def body = []
    new File('/path/to/your/file.csv').readLines().each { line ->
        def entry = [:]
        def values = line.split(',')
        entry.put('phoneNo', values[0])
        entry.put('lastName', values[1])
        entry.put('email', values[2])
        entry.put('firstName', values[3])
        entry.put('mobileNo', values[4])
        body.add(entry)
    }
    sampler.addNonEncodedArgument('', new groovy.json.JsonBuilder(body).toPrettyString(),'')
    sampler.setPostBodyRaw(true)
    
  3. That's it, the JSR223 PreProcessor will generate the request body out of the CSV file

    enter image description here

References:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.