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

I am trying to make a post call to my service. In my example json file input there is

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

I have one csv file that contains a bunch of id and description. So, is there an option where I can convert the CSV file to json objects and pass them to send the call?

+3


source to share


3 answers


Assuming your CSV file is named test.csv

, it is located in the "bin" folder of JMeter and looks like this:

CSV example structure



  • Add CSV Dataset Configuration to your test plan and set it up like this:

    enter image description here

  • You can embed a specific JMeter Variables directly into the request body, for example:

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

    JMeter HTTP Request

  • Therefore, when you run the test, the placeholder variables will be automatically replaced with the values ​​from the CSV file in the HTTP request sampler:

    enter image description here

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

+3


source


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



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

      

+1


source


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

0


source







All Articles