The JSON object:
{
"foo_bar": "content"
}
The code:
type PrettyStruct struct {
Foo string `json: "foo_bar"`
}
func whatever(r *http.Request) {
var req PrettyStruct
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
// ...
}
log.Println(req)
}
This outputs simply:
{}
Go isn't considering my tags when decoding the JSON object, so nothing is unmarshalled into the struct and every field stays with the zero-value.
If, in the JSON object, the field was called "foo" or "Foo", everything works normally.
I've tried the simple tag "foo_bar"
and the following variations `json: foo_bar`
and "json: foo_bar"
.
Any thoughs on what am I doing wrong?