mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 08:45:58 +03:00
[PR #5975] fix(jsonc): preserve numeric precision for large integers in JSON body #5445
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5445
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5975
Author: @VivekNeer
Created: 3/11/2026
Status: 🔄 Open
Base:
main← Head:fix/preserve-numeric-precision-json-body📝 Commits (1)
4e97106fix(jsonc): preserve numeric precision for large integers in JSON body📊 Changes
4 files changed (+142 additions, -12 deletions)
View changed files
📝
packages/hoppscotch-cli/src/__tests__/unit/jsonc.spec.ts(+57 -0)📝
packages/hoppscotch-cli/src/utils/jsonc.ts(+9 -6)➕
packages/hoppscotch-common/src/helpers/__tests__/jsonc.spec.ts(+67 -0)📝
packages/hoppscotch-common/src/helpers/editor/linting/jsonc.ts(+9 -6)📄 Description
Closes #5970
JSON request bodies containing integers larger than
Number.MAX_SAFE_INTEGER(>9007199254740991) were being silently truncated when sent. For example,{"id": 9007199254740993}would arrive at the server as{"id": 9007199254740992}— last digit flipped with no warning.What's changed
packages/hoppscotch-common/src/helpers/editor/linting/jsonc.ts— Instead ofJSON.stringify(node.value)for number nodes (which already lost precision at JS parse time via IEEE-754), the fix slices the original source string using the AST node'soffsetandlength, which are always intact. TheoriginalTextparameter is threaded through all recursive calls inconvertNodeToJSON.packages/hoppscotch-cli/src/utils/jsonc.ts— Same fix applied to the CLI's identical copy of the same utility.packages/hoppscotch-common/src/helpers/__tests__/jsonc.spec.ts— New test file with 10 precision tests (boundary values, nested objects, arrays, combined with comment/trailing-comma stripping, negative integers, small integer regression).packages/hoppscotch-cli/src/__tests__/unit/jsonc.spec.ts— Newdescribeblock with 6 precision tests for the CLI copy.Notes to reviewers
The root cause is in the
"number"case ofconvertNodeToJSON:jsonc-parser'sparseTree()stores number tokens as JSnumberprimitives, so values beyond2^53 − 1are truncated beforeJSON.stringifyeven runs. Usingoffset/lengthto slice the original text sidesteps the IEEE-754 issue entirely.The same bug exists independently in the CLI package — both copies are fixed here.
Full test suite in
hoppscotch-common(50 files / 682 tests) passes unchanged after the fix. ><Summary by cubic
Preserves full precision for large integers in JSONC request bodies by serializing number tokens from the original source text. Prevents silent rounding (e.g., 9007199254740993) in both the app and
hoppscotch-cli.hoppscotch-commonandhoppscotch-clijsonchelpers,convertNodeToJSON()now slicesoriginalTextfor"number"nodes using ASToffset/length, and threadsoriginalTextthrough array/object/property cases and the entry call.hoppscotch-commonand expanded CLI tests to cover objects/arrays, comments/trailing commas,Number.MAX_SAFE_INTEGERbounds, negatives, and verbatim floats; CLI suite aligned with the common one.Written for commit
4e9710672c. Summary will update on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.