Search code examples
jmeterbeanshell

How can we Verify Json response using Beanshell in Jmeter?


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.


Solution

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