Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For jmeter post request, how can I generate input json from csv file?

I am trying to make a post rest call to my service. My sample input json file is,

{ "$id": "1", "description": "sfdasd" }

I have one csv file which contain a bunch of id and description, So is there a option where I can convert csv file to json objects and pass them to post call?

like image 228
Nainesh Patel Avatar asked Jul 07 '17 22:07

Nainesh Patel


2 Answers

Assuming your CSV file is called test.csv, located in JMeter's "bin" folder and looks like:

CSV Example Structure

  1. Add CSV Data Set Config to your Test Plan and configure it as follows:

    enter image description here

  2. You can inline the defined JMeter Variables directly into your request body like:

    {
      "$id": "${id}",
      "description": "${description}"
    }
    

    JMeter HTTP Request

  3. So when you run the test the variables placeholders will automatically be substituted with the values from the CSV file in the HTTP Request sampler:

    enter image description here

See Using CSV DATA SET CONFIG article for more information on JMeter tests parameterization using CSV files.

like image 169
Dmitri T Avatar answered Nov 09 '22 01:11

Dmitri T


Json is just text. Send as is with the variable id taken from csv:

 { "${id}": "1", "description": "sfdasd" }
like image 45
user7294900 Avatar answered Nov 09 '22 01:11

user7294900