Skip to content

Instantly share code, notes, and snippets.

Created May 14, 2015 15:36
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Custom JSON Unmarshaller
package main
import (
type myStruct struct {
Field1 string
Field2 string
func (m myStruct) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Field1 string
Field2 string
Field3const string
Field1: m.Field1,
Field2: m.Field2,
Field3const: "Bob"})
func main() {
m := myStruct{Field1: "Hello", Field2: "Hey"}
ba, err := m.MarshalJSON()
if err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment