Skip to content

fix: case-insensitive key match for structs with more than 16 fields (#427) - #608

Open
chiliec wants to merge 1 commit into
goccy:masterfrom
chiliec:fix-issue-427-case-insensitive-many-fields
Open

fix: case-insensitive key match for structs with more than 16 fields (#427)#608
chiliec wants to merge 1 commit into
goccy:masterfrom
chiliec:fix-issue-427-case-insensitive-many-fields

Conversation

@chiliec

@chiliec chiliec commented Sep 3, 2026

Copy link
Copy Markdown

What

Fixes #427.

Structs with more than 16 fields didn't get their values populated when a JSON key differed in case from the Go field name (e.g. someField1 for SomeField1). Structs with 16 or fewer fields worked fine, and encoding/json matches case-insensitively in both cases, so the two decode paths disagreed.

Fix

The bitmap-optimized key decoder (used for ≤16 fields) already matches keys case-insensitively. The non-optimized fallback path (decodeKey / decodeKeyStream, taken for >16 fields) only did an exact fieldMap[k] lookup. fieldMap is already populated with lowercased key aliases at compile time, so falling back to fieldMap[strings.ToLower(k)] on a miss restores parity with the optimized path and with encoding/json.

Tests

Added TestIssue427 in decode_test.go covering both Unmarshal and the streaming Decoder.

Validation

$ go test -run 'TestIssue427' -v .
--- PASS: TestIssue427 (0.00s)

RED→GREEN (reverting only the source change):

$ git stash push internal/decoder/struct.go && go test -run TestIssue427 .
FAIL    github.com/goccy/go-json
$ git stash pop && go test -run TestIssue427 .
ok      github.com/goccy/go-json

Full suite green, gofmt clean:

$ go test ./...
ok  github.com/goccy/go-json
ok  github.com/goccy/go-json/internal/decoder
ok  github.com/goccy/go-json/internal/encoder
ok  github.com/goccy/go-json/test/cover
ok  github.com/goccy/go-json/test/example

Happy to adjust.

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.

Structs with >16 fields not getting their values while unmarshaling

1 participant