Skip to content

Instantly share code, notes, and snippets.

@christian-korneck
Forked from noamt/partial.go
Last active July 10, 2021 13:55
Show Gist options
  • Save christian-korneck/be8e34dd639ba5740fcc1eeca138c9d5 to your computer and use it in GitHub Desktop.
Save christian-korneck/be8e34dd639ba5740fcc1eeca138c9d5 to your computer and use it in GitHub Desktop.
Partial unmarshal for Medium post "Using Go's json.RawMessage"
contents := []byte(`
{
"key": "value",
"key2": "value2"
}
`)
type Custom struct {
Key string
Key2 json.RawMessage
}
customStructure := &Custom{}
err := json.Unmarshal(contents, customStructure)
if err != nil {
fmt.Println(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment