Search code examples
jsonencodingutf-8jmeterresponse

How to encode JMeter response body (JSON) to UTF-8?


I use a script where I upload a picture to the website and it returns me all the written data in JSON format. We use this app to recognize name/surname on different documents, we have Russian documents as well. However, JMeter returns me something like:

{
    "message": "recognized",
    "birth_date": "1993",
    "native_name": "\u0406\u042e\u041b\u0414\u0410",
    "patronymic": "\u0410\u0410\u0410\u0410\u0410"
}

I tried to change encoding in jmeter.properties and system.properties as well, but it didn`t help. Also I tried to change the encoding via PostProcessor in one string, but no result.

By the way, in Postman I get normal result via 'Beautify' section.

Can anyone help with that issue? Maybe any examples of big PostProcessors, which can do it?


Solution

  • It depends on what you're trying to achieve, if you just need these values in their "text" human-readable representation you can get them using i.e. Groovy's JsonSlurper

    enter image description here

    If you want to substitute the original response with its unescaped equivalent - here is another Groovy's one-liner:

    prev.setResponseData(org.apache.commons.lang.StringEscapeUtils.unescapeJava(prev.getResponseDataAsString()),'UTF-8')
    

    put it into JSR223 PostProcessor's "Script" area and it will do the trick for you

    More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It