4
votes

I have used BSF Postprocessor to parse json in one of my jmeter test files. My code is as follow.

eval('var response = '+prev.getResponseDataAsString());
vars.put("userAccountID", response.ID);

But i have found that BSF post processor reduces Jmeter's performance. So i am going for JSR223 Post processor. I need to know what is the corresponding code for above in JSR223 (JAVA language). Thanks in advance;

2

2 Answers

4
votes

I suggest to use jsr223 assertion and javascript. Then you can just simply check and parse your data. for example:

var response = SampleResult.getResponseDataAsString();
var jsonOutput = JSON.parse(response);

Now you can simply operate on "jsonOutput".

0
votes

There is no out-of-box support of JSON in Java SE hence sample code will depend on JSON library for Java you choose.

May I suggest take a look at JSON Path Extractor Post Processor instead? It is designed to parse JSON data and doesn't require any scripting.

For more information on the JSON Path Extractor see Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON" section)