I am new to Go and stuck at unmarshelling json data. Facing trouble while unmarshelling JSON to struct for the response json that is getting returned as response.
The key for the couple of inner variables are anonymous. Thus unmarshelling them gives no data.
Json response is as below
{
"data": [
{
"Name": "Dummy Value",
"configEvents": {
"5f94f412-532a-41a8-821e-6326dd72556b": {
"eventId": "dummy",
"start": "dummy",
"end": "dummy",
"details": {
"providerCallSign": "dummy",
"callSign": "dummy"
}
}
},
"policyEvents": {
"930195be-f409-421c-abe2-a39d2450d669": {
"details": {
"daiMobileFlag": false
}
}
}
}
]
}
My struct is as follow
type Response struct {
Data []struct {
Name string `json:"Name"`
ConfigEvents struct {
FiveF94F412532A41A8821E6326Dd72556B struct {
EventID string `json:"eventId"`
Start string `json:"start"`
End string `json:"end"`
Details struct {
ProviderCallSign string `json:"providerCallSign"`
CallSign string `json:"callSign"`
} `json:"details"`
} `json:"5f94f412-532a-41a8-821e-6326dd72556b"`
} `json:"configEvents"`
PolicyEvents struct {
Nine30195BeF409421CAbe2A39D2450D669 struct {
Details struct {
DaiMobileFlag bool `json:"daiMobileFlag"`
} `json:"details"`
} `json:"930195be-f409-421c-abe2-a39d2450d669"`
} `json:"policyEvents"`
} `json:"data"`
}
As the key is dynamic in the response, unmarshelling does not capture that particular object. Is there any way to handle this scenario in goLang.