I am trying to extract the value of one variable of a JSON array using Beanshell postprocessor but I am not getting any response in log
My JSON somewhat looks like:
"store":
: [
: : {
: : : "storeId":12345,
: : : "storeName":"ABC",
: : : "storeAddress":"DEFGHIJKL",
: : : "storeMinOrderAmount":100,
: : : "mobile":"+911234567890",
: : : "mobileSecondary":null,
: : : "city":"Somewhere",
: : : "pincode":123456,
: : : "country":"India",
: : : "email":"ptrm@company.com",
: : : "pickup":true,
: : : "delivery":false,
: : : "storeSplashPath":null,
: : : "storeSplashType":null,
: : : "distance":"0.10"
: : },
And my Beanshell Post Processor is:
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import com.eclipsesource.json.*;
print("*******************");
//Get Store total count
int totalStoreNumber = StringUtils.countMatches(new String(data), "storeId");
print("Total Number of Stores are: " + totalStoreNumber);
if (totalStoreNumber > 0) {
//Check for Fulfilment type is "Pickup"
String jsonString = prev.getResponseDataAsString();
JsonObject store = JsonObject.readFrom(jsonString);
JsonArray store = store.get("store").asArray();
String pickup = store.get(1).asObject().get("pickup").asString();
vars.put("fulfilmentType_BSH", pickup);
print("Is Pickup allowed: " + pickup);
}
else {
print("No Stores Nearby");
}
I don't know where I am going wrong. I had read the related queries but couldn't get this right. Any Idea?