Handle escaping characters in JSON - json

In one of my web requests, I get Response Body data as below

{
"JobId":1528,
"CaseId":61687,
"CaseName":"CaseName_3923",
"FirmId":4175,
"FirmName":"FirmName7922442",
"CaseFirmName":"CaseFirmName7922442",
"LastUpdatedDate":"0001-01-01T00:00:00Z"
}
I need to use this whole body response in the next web request, and for that I want to remove the initial  characters.
Is there any way or setting apply in Jmeter by which I can remove these characters? In fact I tried Json Extractor with the settings below, but this is not working, so I assume that the initial  character is creating a problem in not assigning the value of job id to variable vJobid
JSON Extractor:
Apply To: Main sample only
Name of The Cretaed variables: vJobId
Json PathExtractor: $.JobID
Match No. 1

The strange characters at the beginning of your JSON structure is an wrongly encoded BOM (Byte Order Mark). It seems that you got a UTF-8 value which shows as an ISO-8859-1 encoded string.
So the first thing to do would be to find the place where you get the encoding wrong and correct that. If that is not an option, you could try to encode the data back to UTF-8 yourself by using a JSR223PostProcessor before your JSON Extractor with the following Groovy code:
vars.put("correctedResult",
new String(prev.responseDataAsString.bytes("ISO-8859-1"), "UTF-8"));
This postprocessor will try to convert the ill-encoded string back to UTF-8 and store that result in the JMeter variable correctedResult. Choose JMeter Variable Name to use with a value of correctedResult in the JSON Extractor to use that newly encoded value instead of the original data.
But clearly, find the reason for the wrong encoding is the better way.

You can use Regular Expression Extractor instead,
Use Regular Expression:
JobId":(\d+)
Match No. 1
It will match first job id number in response

Related

Regular Expression extractor in Jmeter not capturing value,

I am writing a regular expression extractor for a dynamic value id from the response data as below
I wrote the expression like this
But this is not capturing the value. This id value is to be used in the next request.
If i use the template as $0$, then it captures the value as %202197
Please help to correct the mistake I have made
I tried with template $0$, and match number 0 and 1, but I am getting the same expression
When I try with $1$ as template,the value is not identified at all
Your response seems to be JSON
JSON is not a regular language hence using regular expressions for parsing it is not the best idea
Consider switching to JSON Extractor, the relevant configuration would be something like:
More information: How to Use the JSON Extractor For Testing
If you want to proceed with regular expressions for any reason consider changing your regular expression part from [0-9]+ to (\d+)

How to verify entire JSON response in JMeter 5.3?

Is there a way to verify entire JSON response in JMeter 5.3? I saw some answers in different threads but need to verify the best solution in the latest version of JMeter?
I tried to use JSON assertion as below but it's gives an error.
JSON response is a regular response which you can use Response Assertion
Set Field to Test as Text Response 
the response text from the server, i.e. the body, excluding any HTTP headers.
And in Pattern Matching Rules if you can validate JSON text as is use Equals
Equals - true if the whole text equals the pattern string (case-sensitive)
If you need regular expression use Matches
Matches - true if the whole text matches the regular expression pattern

Save json(content is japanese) in database

I used laravel to save json in to database like as the folowing format
[{"s":"0.000","e":"","t":"\u672c\u65e5\u306f\u3054\u6765\u5854\u304f\u3060\u3055\u3044\u307e\u3057\u3066"},{"s":"0.001","e":"28.000","t":""},{"s":"0.002","e":"29.000","t":"\u3069\u3046\u305e\u6771\u4eac\u306e\u4eca\u3092\u3054\u3086\u3063\u304f\u308a\u304a\u697d\u3057\u307f\u304f\u3060\u3055\u3044\u307e\u305b\u30022"}]
Japanese become "\u3069\u3046\u305e\u..."
Can you tell me the way to covert them to Japanese?
"\u672c\u65e5\u306f\u3054\u6765\u5854\u304f\u3060\u3055\u3044\u307e\u3057\u3066" represents the same string as "本日はご来塔くださいまして". It just depends on the JSON stringifier whether or not it escapes certain characters. Since you're using laravel, I'm assuming you are generating the JSON in PHP. If you are using json_encode you can use the JSON_UNESCAPED_UNICODE option to get JSON with the Japanese UTF-8 characters instead of the escape sequences.
Either way when you parse the JSON you will get the same string. When you display that sting make sure you interpret it as UTF-8.

Jmeter - What is the best extractor to use on a json message?

Currently testing system where the output is in the form of formatted json.
As part of my tests I need to extract and validate two values from the json record.
The values both have individual identifiers on them but don't appear in the same part of the record, so I can't just grab a single long string.
Loose format of the information in both cases:
"identifier1": [{"identifier2":"idname","values":["bit_I_want!]}]
In the case of the bit I want, this can either be a single quoted value (e.g. "12345") or multiple quoted values (e.g. "12345","23456","98765").
In both cases I'm only interested in validating the whole string of values, not individual values from the set.
Can anyone recommend which of the various extractors in Jmeter would be best to achieve this?
Many Thanks!
The most obvious choicse seems to be JSON Path Assertion (available via JMeter Plugins), it allows not only executing arbitrary JSON queries but conditionally failing the sampler basing on actual and expected result match.
The recommended way of installing JMeter Plugins and keeping them up-to-date is using JMeter Plugins Manager
JMeter 3.1 comes with JSON Extractor to parse JSON response. you could use this expression $.identifier1[0].values
as the JSON Path to extract the values.
If your JSON response is going to simple always as shown in your question, you could use Regular Expression Extractor as well. Advantage is it is faster than JSON extractor. The regular expression would be "values":\[(.*?)\]
Reference: http://www.testautomationguru.com/jmeter-response-data-extractors-comparison/

Json : getting the unwanted result

I'm using json plugin to get the response in json.
But I m getting the unwanted result:
Here is what I get:
{"data":"[[\"service\",\"webservices\",\"document\"],[\"validation\",\"adapters\",\"server\"]]","records":25,"recordsTotal":75}
originally the data var in my action class is like this:
[["service","webservices","document"],["validation","adapters","server"]]
but json plugin adds the backslash.
The wanted result is that:
{"data":[["service","webservices","document"],["validation","adapters","server"]],"records":25,"recordsTotal":75}
Is there a way to get the later result ?
Thanks
You're representing the data as a PHP string. " is obviously a reserved character in JSON, so your serialization library is dutifully escaping the quote using /.
If you set up the PHP variable so it's an array of arrays, instead of a string representing an array of arrays, then your JSON serialization will work fine.