Vivi
6 years agoOccasional 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?