Javascript not parsing large number in JSON correctly

abakassahoo
Giga Contributor

Hi Team,

I have a strange issues foreseeing while trying to use JSON.parse to parse a large number..

When I parse this little piece of JSON

{ "value" : 9223372036854775807 }

that's what I get

{ hello: 9223372036854776000 }

9223372036854775807 != 9223372036854776000

Since javascript can't handle 64bit numbers, when executing JSON.parse on the response it rounds the number to the maximum value javascript can handle.

Could you please guide me if there is a existing library from ServiceNow to get the right values..

Below is my example where I would like to extract the values for Sydney from the Array,but while doing through in JSON.parse, its returning 602356450160804600 instead of 602356450160804666

[{"id":543709,"name":"POC_Eschborn"},{"id":623141,"name":"Singapore"},{"id":623075,"name":"Pilot_LithiaSprings"},{"id":602356450160804666,"name":"Sydney"},{"id":634196,"name":"New York"},{"id":636478,"name":"Nieuwegein "}]

2 REPLIES 2

poyntzj
Kilo Sage

you have reached the max for int32.


biginteger - Javascript summing large integers - Stack Overflow



If it was client side you maybe able to include the .js file


BP6
Tera Contributor

How would I include that .js file?