3

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.

Avraham
  • 537
  • 7
  • 23

1 Answers1

3

-----> 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

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Does it have a JSON parser? He doesn't need to do arithmetic on the numbers, he just needs to parse the JSON. – Barmar Feb 29 '16 at 22:41