-1

Below is my sample body in jmeter. I tried using the JSR223 pre processor with below code but its removing the blank values only for the first csv row. How do i remove all blank values coming from my csv file? wham am i doing wrong here? Any help is appreciated.

**[def request = new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def newRequest = evaluate(request.inspect())
request.each { entry ->
    if (entry.getValue().equals('')) {
        newRequest.remove(entry.getKey())
    }
}
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', new groovy.json.JsonBuilder(newRequest).toPrettyString(), '')
sampler.setPostBodyRaw(true)][1]**

http body: {

"number": "${number}",
"marker": "${market}",
"description": "${description}"

}

  • Does this answer your question? [Skip blank lines from CSV using JMeter Csv config](https://stackoverflow.com/questions/66595590/skip-blank-lines-from-csv-using-jmeter-csv-config) – Mohamed Raza Aug 08 '21 at 17:24
  • No. My requirement was to skip sending blank fields. CSV file does not have any blank lines. – Ramesh Babu Aug 18 '21 at 21:11

1 Answers1

0

If you have more than 1 iteration in Thread Group or Loop Controller you will need to revisit your approach to removing and adding back the request body.

Suggested code change:

def data = new org.apache.jmeter.config.Arguments()
def request = new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def newRequest = evaluate(request.inspect())
request.each { entry ->
    if (entry.getValue().equals('')) {
        newRequest.remove(entry.getKey())
    }
}
def body = new org.apache.jmeter.protocol.http.util.HTTPArgument('', new groovy.json.JsonBuilder(newRequest).toPrettyString(), '', false)
body.setAlwaysEncoded(false)
data.addArgument(body)
sampler.setArguments(data)

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133