Skip to content

fix(parser): keep JSON numbers and <, >, & as written in JSON items - #21101

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
L4XB:fix/json-parser-exact-values
Oct 19, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
L4XB:fix/json-parser-exact-values

Conversation

@L4XB

@L4XB L4XB commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

JSONParser turns each array element, each single object and each JSON line into an item whose text is the value re-encoded. It decoded with json.Unmarshal into any / map[string]any, which makes every number a float64, and re-encoded with json.Marshal, which HTML-escapes <, > and &. The indexed text therefore differed from the file:

in the file item text on main
{"id": 12345678901234567890} {"id":12345678901234567000}
{"id": 9007199254740993} {"id":9007199254740992}
"price": 1.50 / 1e5 "price":1.5 / 100000
"note": "a < b && c > d" "note":"a < b && c > d"

The ids are the serious part. A record whose id is above 2^53 (order numbers, snowflake ids, 64-bit keys) is retrieved with a different id. The Python parser this replaced kept them, since Python ints are not floats.

What changed

Two helpers in json_parser.go replace the calls in parseJSONArray, parseSingleJSONObject and parseJSONLines:

  • unmarshalJSON decodes with UseNumber(), so each number stays a json.Number and is written back exactly as it was. It still rejects data after the top-level value, as json.Unmarshal does, so the shape detection and the per-line fallbacks accept and skip the same inputs as before.
  • marshalJSON encodes with SetEscapeHTML(false).

Objects are still written with sorted keys, as before.

Testing

TestJSONParser_KeepsValuesAsWritten has one case each for a single object, an array and JSON lines. With main's json_parser.go all three fail with the values in the table above. The existing JSON parser tests are unchanged and pass.

CGO_ENABLED=0 go test ./internal/parser/parser/ -count=1   # ok
gofmt -l internal/parser/parser/                          # nothing

The JSON parser decoded each array element, object and JSON line with
json.Unmarshal, which turns every number into a float64, and wrote the
item text back with json.Marshal, which escapes <, > and & for embedding
in HTML. An id above 2^53 therefore changed digits
(12345678901234567890 became 12345678901234567000, 9007199254740993
became 9007199254740992), 1.50 became 1.5 and 1e5 became 100000, and
"a < b && c > d" was indexed as "a \u003c b \u0026\u0026 c \u003e d".

Values are now decoded with UseNumber, so each number is written back as
it was in the file, and encoded with HTML escaping off. Data after the
top-level value is still an error, as with json.Unmarshal.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd262965-4943-4115-b7d8-27e7586895ff
📥 Commits

Reviewing files that changed from the base of the PR and between 543e167 and b239dc5.

📒 Files selected for processing: 2
  • internal/parser/parser/json_parser.go
  • internal/parser/parser/json_parser_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The JSON parser now decodes numbers as json.Number, rejects trailing data after top-level values, and serializes JSON without HTML escaping or a final newline. These changes apply to arrays, objects, and JSONL. Existing parse-failure fallbacks and JSONL line skipping remain unchanged.

Changes: JSON parser behavior

Layer / File(s) Summary
Shared JSON decoding and serialization
internal/parser/parser/json_parser.go
Adds shared decoding that preserves numbers and rejects trailing top-level data. Adds serialization without HTML escaping or a final newline.
Array, object, and JSONL parsing
internal/parser/parser/json_parser.go, internal/parser/parser/json_parser_test.go
Array, object, and JSONL parsing use the shared helpers. Tests check numeric spellings and literal <, >, and & characters.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: qinling0210, xugangqiang

Merge Risk: ⚪ Minimal · up to b239d

The change keeps JSON numbers and the characters <, > and & as written when parsing JSON items. I see no actionable merge-blocking risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main parser change: preserving JSON number representations and literal <, >, and & characters.
Description check Passed The description includes the required Summary section, explains the problem and implementation, and reports focused test and formatting results.
Docstring Coverage Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each number’s trail
No digits blur, no symbols pale
The JSON lines stay neat and bright
No escaped signs obscure the sight
The bunny hops through records right

Comment @coderabbitai help to get the list of available commands.

@jay77721
jay77721 self-requested a review October 19, 2026 05:54
@jay77721 jay77721 added the ci Continue Integration label Oct 19, 2026
@yuzhichang
yuzhichang merged commit 4c2b098 into infiniflow:main Oct 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants