Unlike many other programming languages, JavaScript Numbers are always 64-bit floating point and JSON is JavaScript Object Notation, so there is no difference between 30
and 30.0
for JS.
To parse JSON with JMeter, you need to add the JSON Extractor to your test plan.
To get value
from the above JSON:
{
"value": 30.0
}
in the JSON Path expressions field, we can insert this JSON path $.value
After all, you may convert your float to integer using BeanShell :
1. Add BeanShell Sampler after your HTTP Request with JSON Extractor.
2. Copy this code to BeanShell Script:
//get string from JMeter Variable "floatNumberAsString":
String floatNumberAsString = vars.get("floatNumberAsString");
//Parse it to int
int integerNumber = (int)Float.parseFloat(floatNumberAsString);
//Put as a string value to JMeter variable test
vars.put("IntegerNumberAsString", String.valueOf(integerNumber));
Befor script we have floatNumberAsString=30.0
and after IntegerNumberAsString=30
For full details on using BeanShell
, please see: