Open
Description
This test I added to encoding/json
func TestUnmarshalCase(t *testing.T) {
var v struct {
Dist string `json:"dist"`
}
Unmarshal([]byte(`{"dist": "ok", "Dist": "KO"}`), &v)
t.Logf("%+v", v)
Unmarshal([]byte(`{"Dist": "ok", "dist": "KO"}`), &v)
t.Logf("%+v", v)
}
prints
x_test.go:13: {Dist:KO}
x_test.go:16: {Dist:KO}
The comment says Unmarshal "prefers" exact matches, but if there are no words about what happens if multiple fields match.
It's clearly an odd case, but clarity would be nice. I expected the exact match to win always.