-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: bug in json.Unmarshal if keys in JSON differ only by case #26687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Reading the godoc, this appears to be incorrect behavior:
If the case insensitive match overwrites the case sensitive match, it seems like the preference mentioned above isn't working. |
@mvdan Interestingly, if I switch the order of keys in the JSON, so that the new JSON becomes: {"A":"This is value for ACaps","a":"This is value for ASmall"} It works fine. Playground link |
/cc @dsnet |
Indeed seems like a duplicate - thanks @AlexRouSg. |
@AyushG3112 not it's not - https://play.golang.org/p/uyYYa186mez - the latter is used |
@npenzin I already saw that, refer my first reply to this issue after the OP. But again, for a valid JSON with a valid target struct, the order of keys should not matter. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Playground and go version go1.10.2 linux/amd64
What operating system and processor architecture are you using (
go env
)?Playground and:
What did you do?
Here is the input json
In Playground Link 1, my target struct only has a field corresponding to the
a
key.In Playground Link 2, my target struct has fields corresponding to both
a
andA
.What did you expect to see?
In Link 1, I expected to see the value printed to be
This is value for ASmall
which corresponds to the value of keya
What did you see instead?
The value printed was
This is value for ACaps
which corresponds to the value of keyA
.Link 2 worked fine.
The text was updated successfully, but these errors were encountered: