triggerdotdev / jsonhero-web

JSON Hero is an open-source, beautiful JSON explorer for the web that lets you browse, search and navigate your JSON files at speed. 🚀. Built with 💜 by the Trigger.dev team.
https://jsonhero.io
Apache License 2.0
9.01k stars 482 forks source link

Precision is lost, and the id is recognized as a date. #144

Closed fuzhengyin closed 1 year ago

fuzhengyin commented 1 year ago
{
    "id": 1610521604143693812
}

url: https://jsonhero.io/j/rFjT37bQM4sV/tree

截屏2023-01-04 18 15 06
matt-aitken commented 1 year ago

Hi @fuzhengyin,

We always display the original data as parsed by JSON.parse() at the top of the panel (under id in this case). Further down are just alternative ways of thinking about the data based on our best guess.

What you're experiencing here is that JavaScript uses the double number type for all numbers, and it's not 100% accurate. It can represent integers up to 2^53 (9007199254740992) accurately, but anything above that isn't guaranteed.

What happens when JavaScript creates a number from your input

If you need to be able to accurately represent integers this large then you should use strings in JSON, and then in your code use BigInt(). This page has good info on this topic.

This is a brilliant article that explains floating point numbers in lots of detail.