3
votes

I am getting Json as a response. Instead of using multiple jsonPath_assertion I want to check it in single beanshell. Each time I am getting Response with different values.

2

2 Answers

1
votes

You can use beanshell assertion.It will help you a lot. prev.getResponseDataAsString() will return your json response as a string. I hope you would be using Jsonpath online evaluator for evaluating json responses. Suppose if my json online evaluator code looks like this $.items[2].CM_SEQNUMBER In beanshell assertion i have used

 JsonObject jsonobj = JsonObject.readFrom(jsonString);
    JsonArray jsonarr = jsonobj.get("items").asArray();
    String pickupToCheck=jsonarr.get(2).asObject().get("CM_SEQNUMBER").asString();

Similarly you can verify your JSON data without using multiple JSONPath Extractor using single beanshell assertion.

2
votes

I would suggest using JSR223 Assertion and Groovy language instead.

Groovy has built-in JSON support so you will be able to use JsonSlurper class to parse the response like:

def json = new groovy.json.JsonSlurper.parseText(prev.getResponseDataAsString())
// do what you need here

Besides Groovy performs much better than Beanshell and it is recommended to use it for scripting in JMeter. See Groovy Is the New Black for more information.