You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
json.Unmarshal returns an error, which you are ignoring, which is why you're getting the zero value of the data struct. See https://play.golang.org/p/iMGK8M12Pm.
Thanks for the answer; while I don't disagree that I should be catching the error the code I was originally working with had a composite struct with three properties and which correctly populated 2/3 fields in spite of the error.
Is the solution then to make sure you are only doing json unmarshal on a temporary structure that you can discard in the event of errors, or should an error prevent modifying the structure passed in?
mikioh
changed the title
json unmarshal conversion of map with some invalid fields breaks valid fields
encoding/json: unmarshal conversion of map with some invalid fields breaks valid fields
Oct 15, 2016
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.7 (installed via gvm)
What operating system and processor architecture are you using (
go env
)?osx (el capitan) amd64, debian linux amd64, also go playground
What did you do?
https://play.golang.org/p/om2yJ89fb_
What did you expect to see?
I expect to see
"yarp"
as the value inString
.What did you see instead?
When I supply specific combinations of valid json with values that do not match my structure
String
is empty instead of"yarp"
.The text was updated successfully, but these errors were encountered: