11

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?

Nainesh Patel
  • 488
  • 2
  • 5
  • 19

3 Answers3

20

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.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • 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) – Gaudam Thiyagarajan Apr 29 '20 at 16:15
1

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

 { "${id}": "1", "description": "sfdasd" }
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

CSV data can be converted to JSON via a POJO using Jackson. If a POJO is not already defined or required, you can always use the Java Collection classes to store parsed data and later convert it to JSON. http://www.novixys.com/blog/convert-csv-json-java/ is a good reference on how to convert csv to java. You can check the following links too. 1. directly convert CSV file to JSON file using the Jackson library 2. Converting an CSV file to a JSON object in Java

Siva M
  • 51
  • 4