I am having trouble unmarshalling a json data of the below format to a struct. The structure of the json looks a bit confusing to me, so apologies for all the dumb things I am doing to unmarshal it.
{
"message": {
"Server1.example.com": [
{
"application": "Apache",
"host": {
"name": "/^Server-[13456]/"
},
"owner": "User1",
"project": "Web",
"subowner": "User2"
}
],
"Server2.example.com": [
{
"application": "Mysql",
"host": {
"name": "/^Server[23456]/"
},
"owner": "User2",
"project": "DB",
"subowner": "User3"
}
]
},
"response_ms": 659,
"success": true
}
I am trying to unmarshal it using the following struct.
type ServerDetails struct {
Message struct{
Hostname struct{
Details struct{
Application string `json:"application"`
}`json:"-"`
}`json:"-"`
}`json:"message"`
}
The fields Server[0-9].example.com
will be unknown at the time of generating, and will change, and there is this field
{
"application": "Apache",
"host": {
"name": "/^Server-[13456]/"
},
just after the server name that doesn't have a key outside, which again looks confusing to me. I tried a good number of combinations to understand how this could be unmarshalled, but I failed.
What is a working approach to get the json fields unmarshal into a struct?