Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract response data JSON and save variable to CSV file in Jmeter

Tags:

jmeter

I am trying to extract key "count" from response data and write it's value (int) in CSV file.

I have used BeanShell PostProcessor for the same.

Below is script I have used:

count = vars.get("count");

f = new FileOutputStream("file path", true);
p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(count);
f.close();

And JSON sample, I am trying to extract:

{"meta":{"message":"","is_error":false,"count":295,"next":"123","status":1000,"previous":""}

Doing this, "null" gets printed in CSV file.

Please let us know what am I missing here?

It supposed to be 295 gets printed in CSV file.

like image 462
QA-Palash Avatar asked Nov 08 '22 04:11

QA-Palash


1 Answers

Check whether your extractor is fetching the correct value. Below, I have used the same code and used regular expression extractor to fetch the values from the json. It is working fine.

Hope it helps.

enter image description here

Update for Reg Ex

Regular expression config;- enter image description here

Below is to test the regular expression. You can always test your regular expression in view result tree using RegEx Tester:-

enter image description here

like image 182
sunny_teo Avatar answered Dec 28 '22 09:12

sunny_teo