1
votes

My jmeter response is as:

  {"result":"fail", "reason":"\u0027radius\u0027 should be greater than 0 and less than 90000"}

I want to assert response but \u0027 is a garbage value and I want to discard those value in jmeter response. I tried changing the unicode value in jmeter.properties file but it didn't help. Thanks in advance.

1
I open jmeter from command line using : jmeter -Dfile.encoding=UTF-8 and i found file.encoding=UTF-8 in debug sampler but the response is still same: "reason":"\u0027radius\u0027 should be greater than 0 and less than 90000"kishor sharma

1 Answers

3
votes

\u0027 is not "garbage", it's apostrophe character so it might be a bug in your application. Moreover, apostrophe doesn't need escaping according to JSON website

JSON Escaping

So I would recommend double checking the requirement.

In the meantime you still can "assert" the response as Response Assertion in Contains and Matches modes treats input as a regular expression so pattern doesn't have to be exact match, it could be a "match" in terms of regular expressions

And finally you can replace these unicode escapes with apostrophe signs using JSR223 PostProcessor and code like:

def unicode = new String(prev.getResponseData())
log.info('Unicode: ' + unicode) 
def normal = unicode.replaceAll('\\\\u0027','\'')
log.info('Normal: ' + normal)
prev.setResponseData(normal, 'UTF-8')

It will replace all occurrences of \u0027 with ' in the response and substitute response data with the new value:

JMeter Groovy Replace Value in Response

More information: Apache Groovy - Why and How You Should Use It