Skip to content

internal/json: replace segmentio/encoding with encoding/json/v2 - #1287

Open
nahapetyan-serob wants to merge 5 commits into
mainfrom
serob/use-encoding-json-v2
Open

nahapetyan-serob wants to merge 5 commits into
mainfrom
serob/use-encoding-json-v2

Conversation

@nahapetyan-serob

Copy link
Copy Markdown

segmentio/encoding was added in #807 for one method: DontMatchCaseInsensitiveStructFields(). The json/v2 API does strict field-name matching natively, so the dependency isn't needed.

Behavior is unchanged. DefaultOptionsV1() keeps all v1 semantics — duplicate names permitted, invalid UTF-8 replaced, v1 null/merge handling, any-length arrays — and MatchCaseInsensitiveNames(false) overrides the one we don't want. No v2 strictness is adopted here. internal/json/json_test.go is untouched and passes as-is.

UnmarshalUseNumber stays on the v1 decoder and remains case-insensitive: no public API combines UseNumber with strict matching.

go-json-experiment/json hosts a mirror of encoding/json/v2 with the goexperiment.jsonv2 build tag (which is enabled by default on Go 1.27)

Breaking: go.mod goes 1.25.0 → 1.26 (the dependency declares it); Go 1.25 is no longer supported. CI matrix ["1.25","1.26"] → ["1.26","1.27"], which also covers both of the dependency's build paths.

@nahapetyan-serob
nahapetyan-serob force-pushed the serob/use-encoding-json-v2 branch from 5818f09 to d0941b2 Compare September 23, 2026 09:14
Comment thread internal/json/json.go Outdated
return err
}
return NewDecoder(bytes.NewReader(data)).Decode(v)
return jsonv2.Unmarshal(data, v, caseSensitiveV1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using the Decoder also in this case? In this way the behavior is 100% not changed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Will go back to using the Decoder.

This branch has not been deployed

No deployments
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