title: Create Dynamic Json from csv using Groovy in Jmeter
body: <p>I am trying to create a json using CSV data using Groovy scripting and pass the same in the request body in jmeter but I am not able to create the data:</p>
  
  <pre><code>CSV Created:
  
  0.0.0.0,255.255.255.255
  10.0.0.1,255.0.0.0
  10.0.0.2,255.0.0.1
  
  Request body needed as :
  
  {"Rule":{"__type":"AndroidSamsungDeviceRelocationRule","RuleId":0,"Name":"Test","DeviceFamily":6,"Targets":{"Groups":[{"Id":"0000000007.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000"}],"Devices":[]},"Priority":0,"IsEnabled":true,"StartDate":"/Date(1536856632768)/","EndDate":null,"Mappings":[{"RelocationTarget":{"Id":"0000000007.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000","Name":"100MB","Path":"\\\\100MB\\","PathVisible":"\\\\100MB\\"},"IPRange":[{"From":"0.0.0.0","To":"255.255.255.255"}...]}],"EnrollmentCertificateId":null,"EnrollmentCertificateName":""}}
  </code></pre>
  
  <p>Need the IP address for parameters from and to that are their in the csv in a single request.</p>
  
  <p>code I have tried is :</p>
  
  <pre><code>@Grab('com.xlson.groovycsv:groovycsv:1.3')
  import static com.xlson.groovycsv.CsvParser.parseCsv
  
  fh = new File('examples/data/process_csv_file.csv')
  def csv_content = fh.getText('utf-8')
  
  def data_iterator = parseCsv(csv_content, separator: ';', readFirstLine: true)
  
  for (line in data_iterator) {
      sum = line[0] as String
      destination = line[1] as String
  }
  
  def builder = new groovy.json.JsonBuilder()
  
  builder({
     Rule:{
        __type:"AndroidSamsungDeviceRelocationRule",
        RuleId:0,
        Name:"Test",
        DeviceFamily:6,
        Targets:{
           Groups:[
              {
                 Id:"0000000007.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000"
              }
           ],
           Devices:[
  
           ]
        },
        Priority:0,
        IsEnabled:true,
        StartDate:"/Date(1536856632768)/",
        EndDate:null,
        Mappings:[
           {
              RelocationTarget:{
                 Id:"0000000007.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000.0000000000",
                 Name:"100MB",
                 Path:"\\\\100MB\\",
                 PathVisible:"\\\\100MB\\"
              },
              IPRange:[
                 {
                    "From":"sum",
                    "To":"destination"
                 }
              ]
           }
        ],
        EnrollmentCertificateId:null,
        EnrollmentCertificateName:""
     }
  })
  
  sampler.getArguments().removeAllArguments()
  sampler.addNonEncodedArgument('',builder.toPrettyString(),'')
  sampler.setPostBodyRaw(true);   
  </code></pre>
  
  <p>When I am running this through JSR223 Preprocessor I am getting blank request with error HTTP 400.</p>
  
  <p>I need to create a dynamic IPRange loop for number of IPs available in CSV</p>