Skip to content

修复Json美化工具,原始 JSON 中包含嵌套 JSON 时整数精度丢失问题#546

Open
wjfz wants to merge 3 commits intozxlie:masterfrom
wjfz:master
Open

修复Json美化工具,原始 JSON 中包含嵌套 JSON 时整数精度丢失问题#546
wjfz wants to merge 3 commits intozxlie:masterfrom
wjfz:master

Conversation

@wjfz
Copy link

@wjfz wjfz commented Mar 6, 2026

修复前:
Clipboard_Screenshot_1772791163

修复后:
Clipboard_Screenshot_1772790586

{
  "body":{
    "data":{
      "account_id":1401004938049356981
    }
  },
  "rawBody":"{\"data\":{\"account_id\":1401004938049356981}"
}

Copilot AI and others added 3 commits March 6, 2026 09:20
…d escaped JSON strings

The regex that marks large integers (16+ digits) for BigInt handling was blindly
replacing all matches, including numbers inside JSON string values. This corrupted
the JSON structure (inserting unescaped quotes inside strings), causing JSON.parse
to fail and fall back to eval-based parsing which loses integer precision.

Fix: Add an offset-based string context check (consistent with json-worker.js and
format-lib.js) that tracks whether the match position is inside a JSON string by
scanning for unescaped quote characters. Numbers inside strings are left untouched.

Co-authored-by: wjfz <3372236+wjfz@users.noreply.github.com>
Fix BigInt precision loss in parseWithBigInt for JSON with nested escaped JSON strings
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

Successfully merging this pull request may close these issues.

2 participants