1

I have an API GET:/api/getInt

When I call this API using postman, I get following response
    {
        "value": 30
    }
Whereas, If I call the same API using JMeter, I get double
    {
        "value": 30.0
    }

and because of this, I am really in a trouble. As I am facing this kind of issue in many APIs where I am using the response as a request for some other API.

Please, someone, let me know why this kind of strange behavior is there?

dpk
  • 641
  • 1
  • 5
  • 15

2 Answers2

0

If you have different responses my expectation is that you're sending different requests. Make sure that requests sent by JMeter and Postman are exactly the same, you can capture and compare them using a sniffer tool like Wireshark or Fiddler.

Once you figure out what is the difference you should amend JMeter configuration so request would look like exactly the same.

If you have troubles with comparing the requests you can even record the request originating from Postman using JMeter's HTTP(S) Test Script Recorder.

  1. Prepare JMeter for recording. The fastest and the easiest way is using JMeter Templates feature.

    • From JMeter's main menu choose File -> Templates -> Recording and click "Create"

      enter image description here

    • Expand HTTP(S) Test Script Recorder and click "Start"

      enter image description here

  2. Prepare Postman for recording.

    • From Postman "Preferences" dialog choose Proxy tab
    • Use localhost as the proxy host and 8888 as the proxy port

      enter image description here

  3. Run your request in Postman
  4. JMeter should capture it (along with associated headers) under the Recording Controller
  5. Replay request in JMeter - you should get the same response now.
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
-1

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:

Vadim Yangunaev
  • 1,817
  • 1
  • 18
  • 41