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

12,066

Solution 1

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.

Solution 2

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

 { "${id}": "1", "description": "sfdasd" }
Share:
12,066

Related videos on Youtube

Nainesh Patel
Author by

Nainesh Patel

.Net Core Enthusiast.

Updated on June 27, 2022

Comments

  • Nainesh Patel
    Nainesh Patel almost 2 years

    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?

  • Gaudam Thiyagarajan
    Gaudam Thiyagarajan about 4 years
    is there a way, to use each line in a file as json request body data directly. (note: each line is a single json object with multiple key values and i dont want to declare each of the variables manually)
  • Resham Wadhwa
    Resham Wadhwa almost 4 years
    Where should this be added ?
  • user7294900
    user7294900 almost 4 years
    Inside Body data
  • Resham Wadhwa
    Resham Wadhwa almost 4 years
    The right syntax would be : { "id":${id},"description":${description}" }, this syntax will create the json as you have shown in your comment. That is not the syntax rather the output imo. Also, there won't be a dollar sign before id.

Related