0

I am using MQTT to transport messages to a server. I receive a payload with a numeric id 2898871460539924579 yet by the time it gets pumped into my database it has become 2898871460539924500.

I have traced the problem to JSON.parse(). I took the Buffer object that gets passed by MQTT, which I then convert to a string using dataBuffer.toString(). This shows me the correct id (2898871460539924579). When I then run JSON.parse(dataBuffer.toString()), that number is changed to being 2898871460539924500.

If you look at the two numbers side-by-side you'll see that they are almost exactly identical, but for the last two digits:

289 887 146 053 992 45 79
289 887 146 053 992 45 00

This is the same for all the numerical IDs (of this size) that get passed into the system. Is there a way to get JSON.parse() to correctly parse these numbers?

EDIT

This post about large integers in javascript seems to be very relevant to this problem.

GTF
  • 8,031
  • 5
  • 36
  • 59

0 Answers0