4
votes

I'm generating http requests in JMeter using CSV dataset. I'd like to generate nested json like the following one:

{
  "name": "some_name",
  "from": {
    "lat": 20.1,
    "lng": 32.5
  }
  "to": {
    "lat": 41.2,
    "lng": 54.8
  }
}

I parametrized http sampler request body looks as follows in JMeter:

{
  "name": "${name}",
  "from": {
    "lat": ${from_lat},
    "lng": ${from_lng}
  }
  "to": {
    "lat": ${to_lat},
    "lng": ${to_lng}
  }
}

Test data set is as follows:

name,from_lat,from_lng,to_lat,to_lng
some_name,20.1,32.5,41.2,54.8

Instead of required json JMeter compose the following:

{
  "name": "some_name",
  "from": {
    "lat": ${from_lat},
    "lng": ${from_lng}
  }
  "to": {
    "lat": ${to_lat},
    "lng": ${to_lng}
  }
}

What do I need to do to make JMeter substitute the from_lat,from_lng,to_lat,to_lng parameters?

2

2 Answers

2
votes

Make sure you set ignore first line only set to true , as you are adding column names in the dataset, here is my CSV config file settings enter image description here

and the result enter image description here

r

You can refer this blog

For more info on CSV config Follow this link

1
votes
  1. Add CSV Data Set Config to your test plan
  2. Provide full path to your CSV file (or relative to current JMeter working directory)

    JMeter CSV Data Set Config

    No extra configuration should be required.

  3. Your HTTP Request body looks just fine
  4. Verify that JMeter substitutes variables with actual values from CSV using View Results Tree listener

    JMeter verify CSV Data

More information: Using CSV DATA SET CONFIG

If something goes wrong check out jmeter.log file, normally it should contain enough information to get to the bottom of the issue