I am getting a error in a Beanshell Postprocessor, after a HTTP Request returning a JSON array :
My JMeter is launched using mvn jmeter:configure jmeter:gui
using Maven plugin configured like so:
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.5.0</version>
<executions>
....
</executions>
<configuration>
<generateReports>true</generateReports>
<testFilesIncluded>
....
</testFilesIncluded>
<jmeterVersion>5.4.3</jmeterVersion>
<ignoreResultFailures>true</ignoreResultFailures>
<testPlanLibraries>
<artifact>com.googlecode.json-simple:json-simple:1.1.1</artifact>
<artifact>com.fasterxml.jackson.core:jackson-databind:2.14.1</artifact>
<artifact>com.github.javafaker:javafaker:1.0.2</artifact>
</testPlanLibraries>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins-manager:1.6</artifact>
<artifact>kg.apc:jmeter-plugins-standard:1.4.0</artifact>
<artifact>kg.apc:jmeter-plugins-common:1.4.0</artifact>
<artifact>kg.apc:jmeter-plugins-extras:1.4.0</artifact>
<artifact>kg.apc:jmeter-plugins-extras-libs:1.4.0</artifact>
<artifact>com.blazemeter:jmeter-parallel:0.11</artifact>
</jmeterExtensions>
.....
.....
And my script looks like this:
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject;
JSONObject jsonArray;
try {
jsonObject = (JSONObject)jsonParser.parse(prev.getResponseDataAsString());
jsonArray = (JSONArray)jsonObject.get("value");
// List<JSONObject> jsonList = new ArrayList();
// if (jsonArray != null) {
// for (Object object : jsonArray) {
// JSONObject jsonObj = (JSONObject)object;
// jsonList.add(jsonObj);
// }
// }
} catch (Exception e) {
e.printStackTrace();
}
log.info("jsonArray: " + jsonArray);
So, hoping someone might be able to tell me what I am doing wrong?
Error invoking bsh method: eval Sourced file: inline evaluation of: `` import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import o . . . '' : Variable assignment:
jsonArray: Can't assign org.json.simple.JSONArray to org.json.simple.JSONObject
Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error
invoking bsh method: eval Sourced file: inline evaluation of:
`` import org.json.simple.JSONArray; import org.json.simple.JSONObject; import o . . . '' : Variable assignment: jsonArray: Can't assign org.json.simple.JSONArray to org.json.simple.JSONObject
I see nothing wrong with this code. Please help.
This is the problematic line, that throws the error:
jsonArray = (JSONArray)jsonObject.get("value");
I see nothing wrong with the code as well. It seems that the value
attribute of your response is not a JSON Array hence your cast fails and you're getting an error. We need to
in order to suggest the best possible option
There is something wrong with the overall approach: