0
votes

i am working on a jmeter script as below, i am reading from a old database and passing it to this below script

jmeter script in the Http Request Body Data

  "ID": ${ID}
  "ProductName": "${ProductName}"
  "Name" : "${Name}"
  "NoOfdays": ${Numberofdays}

like this up to 300 more parameters

Request Record # 1

"ID": 1 "ProductName": "Pixel" "Name" : "abcd" "NoOfdays": 10 ... up to 300 parameters

Record # 2

"ID": 1 "ProductName": "null" "Name" : "null" "NoOfdays": 0 ... up to 300 parameters

My ESB server throws an error when i send "null" it expects a null with out quotes, how do i replace this values in bulk than using by parameter wise which is a time consuming.

1
How do you parse the JSON? Please show a minimal reproducible example which recreates the error. - Code-Apprentice

1 Answers

0
votes

Remove the quotes from values in Body:

  "ProductName": ${ProductName}
  "Name" : ${Name}

Add a JSR223 PreProcessor to the request which add quotes if value is not null

if (vars.get("ProductName") != null) {
        vars.put("ProductName", "\"" + vars.get("ProductName")  + "\"")
}
if (vars.get("Name") != null) {
        vars.put("Name", "\"" + vars.get("Name")  + "\"")
}

In case the value is "null" you can handle it as:

if (!"null".equals(vars.get("ProductName") )) {
        vars.put("ProductName", "\"" + vars.get("ProductName")  + "\"")
}