Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse JSON with large numbers javascript

I'm getting a JSON object that includes a long type value from an API response. 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.

API response:

    {
       "subject": "subjectTitle",
       "longNumberKey": 7356270823847851521,
    }

When parsing this object to JSON, longNumberKey value would be 7356270823847852000 instead of 7356270823847851521. A solution would be to represent this value as a string but I can't control the API response for that.

like image 907
Avraham Avatar asked Mar 23 '26 04:03

Avraham


1 Answers

-----> json-bignum https://www.npmjs.com/package/json-bignum <------ JSON parser !

GMP (GNU multiple precision) with javascript https://github.com/jtobey/javascript-bignum/blob/master/src/gmp-example.html

gmp.js https://github.com/kripken/gmp.js?MobileOptOut=1

like image 102
ralf htp Avatar answered Mar 24 '26 19:03

ralf htp