I have some JSON that I wish to unmarshal in Go. One of the top-level keys of the JSON dictionary has a value that is also parsable JSON. For example:
{
"Name": "Tony",
"Age": 50,
"Extra": {\"Weight\":180}
}
I have a corresponding struct that I want to unmarsal to:
type Person struct {
Name string
Age int
Extra []byte
}
I want the Extra
key to be a byte array because the JSON structure will vary and the structure of it is not important to the program being written. The program simply needs to push this data along down the line as a byte array.
How can I coax the Go JSON encoder to handle the value of extra
like this?