fix: preserve large integer precision in JSON Beautify#2309
fix: preserve large integer precision in JSON Beautify#2309mkilijanek wants to merge 2 commits intogchq:masterfrom
Conversation
|
Hi @mkilijanek , thank you for your pull request. In the absence of a particular issue, I'm not sure that we need to handle such large numbers in the JSON Beautify operation. The operation is not intended to perform or prepare for processing of the contents of the JSON, but rather to render it in a format that is easier for humans to read. This pull request would not be zero cost - it adds a large amount of code we would need to maintain, and the approach of scanning the JSON input with regexes and building an output string character by character would be costly with large inputs. Given all of this, I'd like to understand more about your use case that requires handling of big numbers by JSON beautify, so that we can weigh up the cost/benefits. |
Thanks, that is a fair concern. My rationale was that "JSON Beautify" looks like a presentation-only operation, so users may reasonably expect it not to alter literal values. Large integers often appear in practice as IDs, counters, timestamps, or other opaque values, and rounding them during beautification can be misleading during analysis. I do agree the current fix has a non-trivial maintenance cost. If that tradeoff is not worth it for this operation, I am happy either to rework it into a narrower solution or to leave this as a documented limitation instead. |
Summary
Fix
JSON Beautifyso large integer literals keep their original precision instead of being rounded during parsing.Existing Issues
Closes #415
Root Cause
JSON Beautifyparses input withJSON5.parse()and then serializes it withJSON.stringify(). Large integers outside JavaScript's safe integer range are coerced to imprecisenumbervalues during parsing.Changes
1234567890123456789Validation
npm run lintJSON Beautifynow preserves1234567890123456789npm testcould not be completed locally under Node 22 because upstreammasterstill usesimport ... assert { type: "json" }syntax and runs with older module flags; this failure is pre-existing baseline behavior in my local runtime, not introduced by this patch