I have following JSON:
{
"common": {
"a": "xyz",
"b": "qwe"
},
"events": [
{
"c": "lll",
"?": "eee",
"??": "ppp"
}
]
}
I know that it has the "a", "b" and "c" fields but I don’t know the names of other fields. I want to unmarshal it in the following structure:
type Request struct {
Common CommonParams `json:"common"`
Events []Event `json:"events"`
}
type CommonParams struct {
A string `json:"a"`
B string `json:"b"`
}
type Event struct {
C string `json:"c"`
X map[string]interface{} `json:?????`
}
How do I do that?
The solutions here don’t work as the fields in this JSON are in a nested structure.
2
Answers
maybe you can use this?
and use loop for extract unknow fields like this