Skip to content
Advertisement

Unable to fetch json response into a json array in Jmeter Beanshell Post processor JSR223 Post processor

  1. I have below json response array which I am getting into Jmeter Regular expression extractor variable C_Totalresponse.

  2. In this I have cartItems JSON object.

  3. In the cartItems JSON object, we have different SKUs and corresponding quantities.

  4. I’m using a hashmap to read values from a CSV file and update quantity details for each SKU, but my script is failing at fetching response into array in Jmeter.

  5. I’m sharing the Jmeter code and error I faced while parsing JSON array at the end

I see many post suggesting groovy I am not sure how to use it for huge response like this

JavaScript

Below is the code in Jmeter for the steps I have mentioned above

JavaScript

Error details are below :

2021-03-17 07:42:03,146 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor javax.script.ScriptException: Sourced file: inline evaluation of: import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads . . . '' : Typed variable declaration : at Line: 48 : in file: inline evaluation of: import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads . . . ” : ( JSONObject ) jsonParser .parse ( jsonString )

Target exception: java.lang.ClassCastException: Cannot cast org.json.simple.JSONArray to org.json.JSONObject in inline evaluation of: “import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.threads . . . ” at line number 48

Advertisement

Answer

I tried many posts for Beanshell processor code to read data from haspmap and use hashmap to update data in json request array values. Many people have suggested to use groovyJSR223 processor. Here is the code below in beanshell which will be helpful to many users whose requestsquestions we left unanswered.

JavaScript
Advertisement