JSR223 Postprocessor to parse json in jmeter

10,816

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

Share:
10,816
Yeasin Hossain
Author by

Yeasin Hossain

Updated on June 06, 2022

Comments

  • Yeasin Hossain
    Yeasin Hossain almost 2 years

    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;

  • toolforger
    toolforger about 2 years
    JSON does not seem to be available by default: Problem in JSR223 script, Set $SIGNATURE_ID, DOCUMENT_ID javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: JSON for class: Script241
  • underwater ranged weapon
    underwater ranged weapon about 2 years
    as i know; in new jmeter javascript is kind of deprecated so maybe you should migrate to groovy. michalsi.github.io/performance-tests/2018/01/08/…
  • toolforger
    toolforger about 2 years
    I'm using new groovy.json.JsonSlurper().parseText(String) in Groovy, which works fine. It just feels clunky :-)