Skip to content

Adding Support for the JSON BigInt Parsing - Update the JSON.parse to JSONBig.parse #54

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

Closed
amithaswar opened this issue Jan 15, 2025 · 3 comments

Comments

@amithaswar
Copy link

https://www.npmjs.com/package/json-bigint
Having issues with showing the BigInt on the Json View. The value is getting converted to Float and then it is losing the precision for the last 3 digits making the last 3 digits as 000

{ "value" : 9223372036854775807}, for example, is still a valid RFC4627 JSON string, and in most JS runtimes the result of JSON.parse is this object: { value: 9223372036854776000 }

@Kikobeats
Copy link
Member

I believe that's happening because BigInt is outside the JSON.parse specification.

This function needs to be modified to support BigInt properly:

export default function parseInput (input) {

Unfortunately, I can't work on this right now, but I'll be happy to accept a PR fixing this 🙂

@Suntgr
Copy link
Contributor

Suntgr commented Jan 22, 2025

I believe that's happening because BigInt is outside the JSON.parse specification.

This function needs to be modified to support BigInt properly:

react-json-view/src/js/helpers/parseInput.js

Line 1 in 4e7c35a

export default function parseInput (input) {
Unfortunately, I can't work on this right now, but I'll be happy to accept a PR fixing this 🙂

@Kikobeats #55
Support High Precision Numbers in JSON Viewer

Description:
This PR addresses the precision loss issue when displaying large numbers or high-precision decimals in the react-json-view component.

Problem:
When the backend returns JSON strings containing high-precision numbers, parsing these strings using standard JSON.parse() before passing to react-json-view's src prop results in precision loss due to JavaScript's number handling limitations.

Solution:
Implemented support for high-precision number handling by:

  • Using specialized libraries (like json-bigint.js or bignumber.js) to properly parse and format high-precision numbers
  • Maintaining numerical precision throughout the JSON parsing and display process
  • Ensuring accurate representation of large numbers and high-precision decimals in the JSON viewer

This enhancement is particularly useful when dealing with:

  • Financial data requiring exact decimal precision
  • Large numerical values beyond JavaScript's standard number limits

The implementation now correctly preserves and displays high-precision numbers as intended by the backend response.

@Kikobeats
Copy link
Member

Resolved by #55
Availabled since https://github.com/microlinkhq/react-json-view/releases/tag/v1.25.0

🎉

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

3 participants