0

I am trying to send this JSON payload in request data from Jmeter and I want to read PaymentID and Parts:[ "field2"] from .csv file that has some extra coulmns, any help in this regard? 1) How to read specific columns as input values from .csv file? 2) How to read JSON object values from .csv file?

Payload:

{
   "Location":"xxx",
   "Payment":
   {
       "Source": "xxx",
       "SourceID": "123456789",
       ***"PaymentID": "",***
       "PaymentType": "xx",
       "PaymentForm": "API",
       "CustomerNo": "xx",
       "PaymentDate":"18 SEP 2018",
       "Amount": "xxxx",
       "TaxCode": "Sxx",
       "Operator": "",
       "TillNo": "",
       "Description": "",
       "Parts": [
            {
            "field": "xxx",
            ***"field2": "xx",***
            "field3": "xx"
            }
        ]
    }
}
Safiyya
  • 1,383
  • 1
  • 10
  • 16
Hmh Khan
  • 1
  • 2

1 Answers1

0

It is hard to provide the exact solution without seeing your CSV file, basically there are 2 options:

  1. (Preferred) You can declare all columns as JMeter Variables in the CSV Data Set Config and use only those, which are related to the columns you're interested in
  2. (Alternative) You can use __CSVRead() function where you can specify which column to read

    enter image description here

  3. You can inline JMeter Variables or Functions directly into JSON Payload:

    {
       "Location":"xxx",
       "Payment":
       {
           "Source": "xxx",
           "SourceID": "123456789",
           "PaymentID": "${Variable_From_CSV_Data_Set_Config",
           "PaymentType": "xx",
           "PaymentForm": "API",
           "CustomerNo": "xx",
           "PaymentDate":"18 SEP 2018",
           "Amount": "xxxx",
           "TaxCode": "Sxx",
           "Operator": "",
           "TillNo": "",
           "Description": "",
           "Parts": [
                {
                "field": "xxx",
                "field2": "${__CSVRead(your_file.csv,4)}", ${__CSVRead(your_file.csv,next)}
                "field3": "xx"
                }
            ]
        }
    }
    
Dmitri T
  • 159,985
  • 5
  • 83
  • 133