ATLANTBH jmeter-components: JSON Path Assertion - json

I'm trying to perform a JSON assertion using ATLANTBH jmeter JSON PATH Assertion. However I cant seem to write a correct expression to get the following fields from the JSON feed posted below:
123456789
1009
SOME RANDOM MESSAGE
{"api": {"status":"Success","callsremaining":36,"version":"x.x.x.x"}
,"result":{"errors":{"123456789":{"code":1009,"error":"SOME RANDOM MESSAGE"}}}
}
Has anyone here got any experience using this JMeter plugin?
I know I could use regex and Beanshell to validate but I'd rather use these JSON Path Assertion.
Any help you could provide would be most appreciated.

Looks like you can easily assert both 1009 and SOME RANDOM MESSAGE values using JSONPath expressions (in JSON Path Assertion components) but not sure about 123456789: that's not node value but bode name, and JSONPath implementation used by these components seems has no expressions to get node name.
Suppose you can easily use to assert 123456789 instead binding of JSON Path Extractor (from the same components collection) with jmeter's standard Response_Assertion.
Add 2 JSON Path Assertions as children to the sampler which returns json response you want to process:
Expressions will be $.result.errors..code and $.result.errors..error correspondingly.
Add JSON Path Extractor as child to the same sampler to extract full error entry:
Expression: $.result.errors..
This will extract {"123456789":{"error":"SOME RANDOM MESSAGE","code":1009}} and save into the pointed variable (${errorKey}).
Add Response Assertion as child to the same sampler, after previously added JSON Path Extractor:
This will assert name of the key (123456789) in the value of ${errorKey} variable.
So the final construction may look like
...
YOUR Sampler
JSON Path Extractor
JSON Path Assertion
JSON Path Assertion
Response Assertion
...

Related

I am trying to assert if two strings of a response are same or not using response assertion in jmeter but it's showing an error

In response assertion I have given field to test as text response and pattern matching as contains
Pattern to test is
${bookmark_ALL}${value}=${value}${other_bookmark_ALL}
I have taken those bookmark values using json extractor given match -1 for it as well, both bookmark values are in string format
If you want to compare 2 JMeter Variables using Response Assertion the correct setup would be something like:
You can check JMeter Variables values using Debug Sampler
Also contains mode assumes regular expression, most probably you were looking for substring
More information: How to Use JMeter Assertions in Three Easy Steps

Need to extract a josn value for nested requests in JMeter using Jsonpath extractor

I have response which derived from a action. I need to extract a value of userid node using json path extractor in JMeter
{
"ABC": "{"response":{"userId":user1,"caseId":0,"name":"Json","email":"json#xyz.com","mobileNumber":"1223456789","countryCodeId":"1","countryCode":"+90","emailOTP":830782,"mobileOTP":301879,"mobileOTPString":null,"otpCreationDate":"2021-10-14T10:01:38.5802765Z","configOTPTimeOut":120,"redirectUrl":null,"isOTPExpired":false,"countryCodeValidMessage":null,"mobileNumberValidMessage":null,"offset":"00:00:00","postStatus":false,"postMessage":null,"id":null,"response":null,"isProceedToCreateMeeting":false},"successcode":0,"message":null}"
}
I have tried $..ABC.response.userId, it says NoMatch. what is the correct syntax to extract userId node which is present inside response
What you're showing us is not a valid JSON (you can check it yourself using i.e. https://jsonlint.com/ website or equivalent) therefore you won't be able use either JSON Extractor or JSON JMESPath Extractor
Unless it's a copy-paste issue you're limited to Regular Expression Extractor, example regular expression would be something like:
"userId"\s*:\s*(.+?)\s*,

Jmeter parse and Assert Array of Json objects

In Jmeter when trying to extract data from Json object everything is ok and works great but, when i have array of Json objects can't extract it.
Result is:
[{"id":1,"name":"test"},{"id":2,"name":"test2"}]
it is my project JSON Extractor and JSR233 Assertion.
Inside Groovy script i'm making log.info but it doesn't captures variable value which is described inside JSON Extraxtor.
String id = vars.get("id");
log.info ("The example answer is " + id);
if (id == ""){
AssertionResult.setFailureMessage("The id is null");
AssertionResult.setFailure(true);
}
Please note that if Json response looks like this {"id":1,"name":"test"}
everything works correctly.
Change your JSON Path Expression to look like: $..id. .. is a deep scan operator so it will return all id attributes values.
Change Match No to -1
It will result in the following variables:
id_1=1
id_2=2
id_matchNr=2
I have no idea what exactly you need to assert, hopefully you will be able to amend your Groovy script yourself.
Also be aware that there is JSON Assertion test element available since JMeter 4.0 so you won't need to have separate extractor and assertion elements.

How to Extract value from Json Path Post Processor?

I need to extract id where asOf : 2016-11 for latest run.
e.g given below response of request I need to store 21aa83fe-fe1b-4447-9b2e-05e7d6cd67d3 in a variable because as of 2016 is in the last and-and the corresponding id is. Could you please tell me how to write JSON Path Post Processor Expression out of it?
{"id":"1fabbb02-0b7d-4bec-badd-9fe9f1c63f08","batch" {"id":"GL1600"},"asOf":"2014-06-16T00:00:00Z","version":3,"statusIdentifier":"END"},
{"id":"212fc2b5-03d6-4d76-ab6d-e9e783459120","batch":{"id":"N1400"},"asOf":"2014-06-16T00:00:00Z","version":3,"statusIdentifier":"END"},
{"id":"21aa83fe-fe1b-4447-9b2e-05e7d6cd67d3","batch":{"id":"N1500"},"asOf":"2016-11-16T00:00:00Z","version":3,"statusIdentifier":"END"},
If your response is valid JSON you can use == filter operator like
$..[?(#.asOf == '2016-11-16T00:00:00Z')].id
References:
JSON Path - Filter Operators
Advanced Usage of the JSON Path Extractor in JMeter
If response is not valid JSON you will need to go for Regular Expression Extractor instead.

How to parse json array into string for use as parameters later in jmeter?

Sample input as below:
[{"program":"C:/temp/abc.exe","actions":"9","file_name":"abc1","new_file_name":"newabc1","version":"2.0.0.0","product_name":"abc","description":"abc","eventdate":"20160601120000"},{"program":"C:/temp/abc.exe","actions":"9","file_name":"abc2","new_file_name":"newabc2","version":"2.0.0.0","product_name":"abc","description":"abc","eventdate":"20160601120000"}]
I need to parse this json array into string for use in the following http request as parameters. I new to jmeter and tried to follow the example in http://theworkaholic.blogspot.my/2012/05/json-in-jmeter.html but i can't seem to get the value of jsonResponse at last.
[UPDATE]
[]1
Your question is not clear enough, however here are some clues:
If you need to store the whole response into a JMeter Variable for later re-use - go for Regular Expression Extractor configured as follows:
Reference Name: anythingMeaningful, i.e. jsonResponse
Regular Expression: (?s)(^.*)
Template: $1$
If you need 2 separate JSON Objects from the array - JSON Path PostProcessor is available since JMeter 3.0
$.[0] - for 1st JSON Array item
$.[1] - for 2nd JSON Array item
If you need anything else - use the same JSON Path PostProcessor. I would recommend getting familiarized with the following material:
JSONPath - XPath for JSON
Advanced Usage of the JSON Path Extractor in JMeter
Still no luck - update your question with exact details on how you need to re-use that JSON data in next request(s)