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

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?

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
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

Related

Unable to Extract value from JSON response which has the data in "\"

Please help me to get out the problem which I am facing. I have a JSON response like this:
"{"Version":10,"Collections":[{"Id":"*******","Name":"","Description":null,"IsValid":false,"ABC":"\\XYZ\\collection\\","C
and want to fetch the values of collections which has n number of Id's but JSON extractor is not working here.
Don't post text as image otherwise even those who are willing to help won't re-type your code or use OCR software in order to reproduce your issue
What you're showing to us is not a valid JSON, you can check it yourself using an offline or online JSON Lint Tool hence you won't be able to use JSON Extractor for this.
If you get escaped JSON as a part of some JSON attribute, like this one:
{
"some-attribute": "{\"foo\":\"bar\"}"
}
You won't be get this bar value directly so you will need to do this in 2 steps:
Use 1st JSON Extractor to get the value of some-attribute
Use 2nd JSON Extractor to get the value of foo attribute
Demo:
More information: API Testing With JMeter and the JSON Extractor

Is there a way to validate the whole JSON response using SOAPUI?

I tried using "COntains" option in SoapUI but it is not working so I tried Jsonpath ut I can't figure out how to.
Previously when I did XML request, I just use "COntains" and copy the whole response on the assertion.
But I cannot find to wor on it on JSON.
It looks like SOAPUI suggests to use JSONPath to validate responses.
To match an entire document you could simply search for the root $
and match it against the entire document (special formatting might throw a wrench here).

Jmeter JSON Format Post Processor breaks Token retrieval

I am working with Jmeter and i want to format the JSON results. So i installed JSON Format Post Processor and added it to the root of the project.
It works correctly, it formats the JSon response for easy readability. However there is also a request with requires Token authentication. It does not work with the JSON Format Post Processor.
Example:
Correct coin retrieval without JSON Format Post Processor:
{"access_token":"Secret","expires_in":3600,"token_type":"Bearer"}
And with:
{
"access_token": "Secret",
"expires_in": 3600,
"token_type": "Bearer"
}
I use a regulair extractor to extract the token: access_token":"([a-zA-Z0-9.\-\_]*)
This seems to break in combination with the formatter. No valid token access is denied in all requests
Is there an easy way around this? It seems i can either use Jmeter JSON Format Post Processor for my complete project, or not at all.
Anyone know how i deal with this?
If it is possible, apply JSON Format Post Processor after regex extractor. This could help.
For easier access to data in JSON format you can use JSON Path Extractor or SmartMeter's Boundary Body Extractor
To extract JSON data the best option is native JSON Extractor:
http://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor
Regarding your precise issue, a better regexp would be:
access_token":"([^"]+?)"
It seems that you have optional white space after :
Regular expression:
access_token":(\s*)"([a-zA-Z0-9.\-\_]*)
Template change to use $2$

How do I pass json in the url of a REST request?

I am creating a kafka broker in a cluster by sending a request to the url. According to the api it says that I can add additional options to my broker in the form /api/broker/<cli command>?broker={broker-expr}&<setting>=<value>, however the setting that I need to set has json as its value. How would I do this?
I've tried quite a few different ways of writing it at none of them work. The json value is meant to be
{
"period":"10s"
}
I've tried
/api/broker/remove?broker=0&stickiness={"period":"10s"}
/api/broker/remove?broker=8&stickiness={period:10s}
/api/broker/remove?broker=8&stickiness="{period:10s}"
Update:
I've tried encoding the url but it still doesn't work. Everything is decoded except for the :.
The string I enter for the json: %7B%22period%22%3A%22600s%22%7D
This is what it ends up as after I send it.
How do I encode a : ?
Only the first option you suggested is correct JSON. However, the JSON will need to be encoded.
Encoding just the JSON part results in %7B%22period%22%3A%2210s%22%7D
Check out the following site for more on URL encoding
http://www.w3schools.com/tags/ref_urlencode.asp

is it possible to pass json format in browser's url address bar? (GET method)

want to test my url service in browser but need to pass json format data.
I tried the below but no success:
http://locahost:8042/service/getinfo?body={"name":"H&M"}
or any tool that can be use to pass json formatted test data?
UPDATES1
I mean is to pass the json formatted data manually in browser's url address bar. Like as my example above. This is for quick testing only not for implementation.
Yes, you certainly can pass JSON in a URL Querystring. You just have to URLencode the JSON string first. As #dmn said, the data is probably better passed via POST because of GET's size restrictions.
The { and } characters are considered unsafe for unencoded use in a URL.
http://www.faqs.org/rfcs/rfc1738.html
Probably putting it in the GET won't be a good idea, since url parameters have a limit of 256 characters. It would be better if you use POST and put the JSON in the body and after that you can parse it using Jackson for example or gson ... and get the result as an object.
Yes you can Add Extension to chrome web-browser called 'Advance rest Client' and change contain header to application/json and make json object and post in pay load then hit send bottom it works for json object
enter image description here
This is how I am doing in my web service, I am passing a json and within the service I manage it.
Just do a URL query like this:
http://locahost:8042/service/getinfo?name=h%26m
%26 is the encoding of &