Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When json contains more than the maximum integer allowed by js, precision is lost #33

Open
njzydark opened this issue Feb 21, 2024 · 2 comments

Comments

@njzydark
Copy link

https://json-diff-kit.js.org/#l=%7B%0A++%22a%22%3A+90071992547409912345%0A%7D&r=%7B%0A++%22b%22%3A+90071992547409912345%0A%7D

image
@RexSkz
Copy link
Owner

RexSkz commented Feb 21, 2024

It seems a bit difficult to support large numbers if we do not write the parser ourselves.

Both integers and floats are valid in JSON, so we cannot just use the library json-bigint to parse the JSON string. Do you have any ideas?

@njzydark
Copy link
Author

njzydark commented Feb 22, 2024

It seems a bit difficult to support large numbers if we do not write the parser ourselves.

Both integers and floats are valid in JSON, so we cannot just use the library json-bigint to parse the JSON string. Do you have any ideas?

I have now implemented it based on CodeMirror, because it accepts strings, so I can use JSONBigNumber for processing by myself. If I want to implement it in your library, the solution I came up with is:

  1. When creating a new Differ, add additional options for users to pass their own JSON stringify and parse methods.
  2. When creating a new Differ, add additional options to determine if the data is a BigNumber. This check is to prevent iterating through BigNumber objects (values processed using bignumber.js are special objects).

Because the underlying design of your library is to accept raw JSON objects instead of strings, the above method can only be handled by users through options, and cannot be integrated into your library (the values in the transmitted object must have been processed by bignumber, otherwise precision will be lost during transmission).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants