How to create a infinite nested json and access the same in go lang data structures,
For example below is the sample json with 3 levels, in general it should be dynamic, user can add any children by selecting the value from the dropdown which is populated tree like dropdown on UI.
{
"value": {
"Id": "1",
"Text": "abcd",
"Parent": ""
},
"children": [
{
"value": {
"Id": "2",
"Text": "abcd",
"Parent": "1"
},
"children": [
{
"value": {
"Id": "3",
"Text": "abcd",
"Parent": "1"
}
}
]
}
]
}
structures in go: I have created this go data structure but it will access only upto 3 levels based on the above json, can we make this data structure as dynamic where it should handle infinite nested json.
type AutoGenerated struct {
Value struct {
ID string `json:"Id"`
Text string `json:"Text"`
Parent string `json:"Parent"`
} `json:"value"`
Children []struct {
Value struct {
ID string `json:"Id"`
Text string `json:"Text"`
Parent string `json:"Parent"`
} `json:"value"`
Children []struct {
Value struct {
ID string `json:"Id"`
Text string `json:"Text"`
Parent string `json:"Parent"`
} `json:"value"`
} `json:"children"`
} `json:"children"`
}
Note: we can add n number of parents and n number of children, is this possible in Go data structures?
can you suggest best and easy way to implement this?
How can we add/delete/edit any parent or child? (The above json example will come from UI) ? To add/delete/edit any parent or child which json structure or id needed?