How can I parse this json object:
{
"ports": {
"0": {
"3306": "3306"
},
"1": {
"3307": "9908"
}
}
}
I can have N ports, and the values for each port will always be a key:value pair.
So far I've tried this:
type Ports struct {
Port map[string]string
}
With this I get the keys (0, 1) but the values are empty.
I also tried this:
type Ports struct {
Port map[string]struct{
Values map[string]string
}
}
But also not working.
This is how I am decoding the json object:
var requestBody Ports
decoder := json.NewDecoder(body)
err := decoder.Decode(&requestBody)