I have below JSON
[{
"id": 8,
"title": "Indonesia",
"type": "country",
"attributes": {
"regionCode": "ID",
"information": {
"title": "Welcome to Indonesia",
"content": "We only serve selected areas in Indonesia.",
"image": "indo.png"
}
},
"children": [
{
"id": 9,
"title": "Jakarta",
"type": "city",
"attributes": {
"regionCode": "ID-JKT",
"information": {
"title": "Welcome to Capital City of Indonesia",
"content": "We only serve selected areas in Jabotabek",
"image": "jakarta.png"
}
}
},
{
"id": 10,
"title": "Bali",
"type": "city",
"attributes": {
"regionCode": "ID-BAL",
"information": {
"title": "Welcome to the beach city Bali",
"content": "We only serve selected areas in Bali.",
"image": "bali.png"
}
}
}
]
}]
Technically this is a nested structure to itself as the children node, and the children might have children as well. But i just couldnt get it right when im using unmarshal to decode this.
The working one is like below i have no problem defining the attribute as a separate struct so assuming i have locationAttribute struct
type locationNode []struct {
ID string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Attributes locationAttribute `json:"attributes"`
Children []struct {
ID string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Attributes locationAttribute `json:"attributes"`
Children []interface{} `json:"children"`
} `json:"children"`
}
However im expecting to be something like below
type locationNode []struct {
ID string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Attributes locationAttribute `json:"attributes"`
Children []locationNode `json:"children"`
}
any help will be much appreciated