# How can I validate a number that is treated as text in JSON response, in my Test Script assertion?

**URL:** <https://community.postman.com/t/how-can-i-validate-a-number-that-is-treated-as-text-in-json-response-in-my-test-script-assertion/35613>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 24, 2022, 3:49pm UTC](https://community.postman.com/t/how-can-i-validate-a-number-that-is-treated-as-text-in-json-response-in-my-test-script-assertion/35613 "2022-05-24T15:49:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jes73](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jes73](https://community.postman.com/u/jes73)\
**Post date:** [May 24, 2022, 3:49pm UTC](https://community.postman.com/t/how-can-i-validate-a-number-that-is-treated-as-text-in-json-response-in-my-test-script-assertion/35613/1 "2022-05-24T15:49:26Z")

</div>

Hello, new to Postman, newer still to JavaScript

My question:  
In a test script I want to validate a response is within a given range, but the problem is the number format is Brazilian, ( **1,1 instead of 1.1** ) and is so surrounded by “” and treated like text.

My Code Attempt:  
pm.test(“Test\_07 AI % is in range 3,5 to 4,5”, function () {  
var annualMode = pm.response.json();  
pm.expect(annualMode.recScheme.incPctAnMode).is.lessThan(“5,0”);

Obviously this fails. AssertionError: expected ‘3,7’ to be a number or a date

I’d be very grateful for any help.

---

<div class="post-metadata">

**Author:** ![archerZ](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@archerZ](https://community.postman.com/u/archerZ)\
**Post date:** [June 11, 2022, 12:26pm UTC](https://community.postman.com/t/how-can-i-validate-a-number-that-is-treated-as-text-in-json-response-in-my-test-script-assertion/35613/2 "2022-06-11T12:26:55Z")

</div>

Hi @jes73,

First you will need to change the string from 1,1 to 1.1. You can do this with simple javascript string replace text.replace(",", “.”).

Then you will need to convert the text to an integer again with simple javascript. parseInt(text).

So your test should look like this…

pm.test(“Test\_07 AI % is in range 3,5 to 4,5”, function () {  
var annualMode = pm.response.json();  
var value = annualMode.recScheme.incPctAnMode.replace(’,’,’.’) // Setting new value and replacing the character.  
pm.expect(parseInt(value)).is.lessThan(5.0);

---

<div class="post-metadata">

**Author:** ![jes73](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jes73](https://community.postman.com/u/jes73)\
**Post date:** [June 15, 2022, 10:02pm UTC](https://community.postman.com/t/how-can-i-validate-a-number-that-is-treated-as-text-in-json-response-in-my-test-script-assertion/35613/3 "2022-06-15T22:02:01Z")

</div>

Oh my! Thank you so much @archerZ - you made that look very simple! 😃  
That has helped enormously.
