Reputation: 194
I have a simple JSON and I would like to get two properties :
core
and matching
and verify if core : true
and matching : true
.
{
"lockVersion"
: 1,
"updatedBy" : "jan",
"updatedOn" : "2016-09-25T11:21:45Z",
"id" : 964,
"title" : "Corporate Numeric",
"description" : null,
"descType" : 31084140,
"descValueType" : 31084136,
"defaultSourceOfVerification" : "Source",
"core" : true,
"matching" : true,
"anything" :
[
],
"authorized"
:
[
1
]
}
Is it possible to do this using AND operator or must I perform a two step action to extract one set then filter again to get my final results? I'm going to use jp@gc - JSON Path Assertion.
Upvotes: 2
Views: 1406
Reputation: 34566
See Dmitri T answer for JSON Path Assertion plugin.
So Using Core JMeter you can do it like this using JSON Extractor and Response Assertion with scope "JMeter Variable":
Upvotes: 1
Reputation: 168157
Configure your JSON Path Assertion as follows:
[?($.core == true && $.matching == true)]
Validate against expected value
box[]
Invert Assertion
boxReferences:
Upvotes: 2
Reputation: 541
You should be able to use the BeanShell assertion and the built-in JSON parser to achieve this.
import net.minidev.json.parser.JSONParser;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONArray;
try {
// Use JSONParser to parse the JSON
JSONParser parser = new JSONParser(JSONParser.ACCEPT_NON_QUOTE|JSONParser.ACCEPT_SIMPLE_QUOTE);
JSONObject rootObject = (JSONObject) parser.parse(prev.getResponseDataAsString());
if ( rootObject.get("matching") && rootObject.get("core") ) {
Failure=false;
}
else {
Failure=true;
}
}
catch ( Exception ex) {
log.info("Exception.." + ex);
Failure=true;
}
Upvotes: -1