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
encoding/json: doesn't deserialize json fields with underscores into struct's fields who's tag contains the underscore but the struct field name does not
#9841
Closed
coreyog opened this issue
Feb 11, 2015
· 1 comment
[Unmarshal will look through the destination struct's fields to find] An exported field with a tag of [the json field's name]
If I change the struct definition to
type Example struct {
Some_ID int "Some_ID"
}
Then, after Unmarshalling, e.Some_ID will contain 4 as expected.
It appears that when an underscore is involved in the field in the json, tagging the struct's field with an underscore when the struct's field does not contain an underscore will not marshal that field. If the json contains an underscore, so must the struct's field and the tag is useless.
The text was updated successfully, but these errors were encountered:
Your struct tag has the wrong syntax, but the issue tracker is not a support forum. Please ask these sorts of questions on the go-nuts@ mailing list or StackOverflow.
Json:
Go:
Given the above json and struct, the value
e.SomeID
will not be filled with the value4
.From the first of three rules listed at http://blog.golang.org/json-and-go:
If I change the struct definition to
Then, after Unmarshalling, e.Some_ID will contain
4
as expected.It appears that when an underscore is involved in the field in the json, tagging the struct's field with an underscore when the struct's field does not contain an underscore will not marshal that field. If the json contains an underscore, so must the struct's field and the tag is useless.
The text was updated successfully, but these errors were encountered: