Upon receiving a JSON
object from an API, I encountered a problem with the value of type long
.
Due to Javascript's limitations in handling 64-bit numbers, when using JSON.parse
on the received response, the number is rounded to the maximum value that JavaScript can handle.
The API response:
{
"subject": "subjectTitle",
"longNumberKey": 7356270823847851521,
}
After parsing this object to JSON
, the longNumberKey
value would be altered to 7356270823847852000
instead of the original 7356270823847851521
.
One potential solution could have been representing this value as a string
, but unfortunately, I do not have control over the format of the API response.