Skip to content

Instantly share code, notes, and snippets.

@sourcec0de
Forked from kendellfab/golang-json-marshall
Last active August 29, 2015 14:06
Show Gist options
  • Save sourcec0de/e444652dcae1e6fe2151 to your computer and use it in GitHub Desktop.
Save sourcec0de/e444652dcae1e6fe2151 to your computer and use it in GitHub Desktop.
type Whatever struct {
someField int
}
func (w Whatever) MarshalJSON() ([]byte, error) {
return json.Marshal(struct{
SomeField int `json:"some_field"`
}{
SomeField: w.someField,
})
}
func (w Whatever) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"some_field": w.SomeField,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment