cancel
Showing results for 
Search instead for 
Did you mean: 

The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Occasional Contributor

The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Hi,

I am using ReadyAPI 2.1.0.

I have the following response in RAW:

{
"amounts": {
"amount": 20000.00,
"amount2": 500.50,
"amount3": 100.55
}
}

 

But the response in JSON looks like this:

{
"amounts": {
"amount": 20000.0,
"amount2": 500.5,
"amount3": 100.55
}
}

It seems that the JSON is deleting the last zeros from the decimal part. I am trying to write a script that will validate that the amounts are up to 8 and must have 2 decimals. This is my script:

import groovy.json.JsonSlurper
def response=messageExchange.response.responseContent
def json=new JsonSlurper().parseText(response)

def amount=json.amounts.amount

assert amount==~ /\d{0,8}\.\d{2}/

But this fails for amount and amount2 as the zero  is not in the json response and when I use log.info for amount I get 20000, for amount2: 500.5 and for amount3: 100.55.

 

Does someone know how to fix this?

 

 

7 REPLIES 7
Super Contributor

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Please change the code to this line :-

import groovy.json.JsonSlurper
def response=messageExchange.response.responseContent
def json=new JsonSlurper().parseText(response)

float amount=json.amounts.amount

assert amount==~ /\d{0,8}\.\d{2}/
Occasional Contributor

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Hi, 

 

The float is not solving the problem. For example the "amount": 20000.00 (RAW) is now shown as 20000.0 in json and when I have the log.info for this node. 

 

So the assertion is still failing even if I declare it as float or double.

 

Community Manager

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Community, any more suggestions?

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Occasional Contributor

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Hi Tanya,

 

While searching for a solution I came up with this post from 2015 https://community.smartbear.com/t5/SoapUI-Pro/JSON-Response-tab-displaying-decimal-values-incorrectl...

It's the same problem as I have and according to the post above this should have been fixed in version 1.5. 

 

Has anyone else come up with the same problem for ReadyAPI version 2.1.0 and REST services?

 

Any help is welcomed.

Moderator

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Hi Vivi,

 

The corresponding bug was fixed in ReadyAPI 2.3.0. And, we always recommend that users upgrade to the latest version: https://support.smartbear.com/downloads/readyapi/

 

But, the provided script assertions don't work for me in ReadyAPI 2.6.0 anyway for some reason.


Anastasia
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Community Manager

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Thanks for the reply, Nastya.

 

@Vivi, which ReadyAPI version do you use? I think It's worth installing the latest maintenance build. You can download it here:

https://support.smartbear.com/downloads/readyapi/maintenance

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Occasional Contributor

Re: The response from JSON tab does not match to the one from RAW when there are zeros in decimal

Hi!

 

Thank you for the responses!

 

Unfortunately I cannot try the new version as the project is at a critical point this period. But I hope that I can download the new version and try it maybe in a month.

 

Thanks again for all help!!! Smiley Happy

New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors