Answer the question
In order to leave comments, you need to log in
How to parse hierarchical data in Golang?
Hello comrades! Please help me to solve the problem. Oracle
database has a table with the following structure:
| organization_id | ogranization_name | parent_id | level |
|-----------------|-------------------|-----------|-------|
| 1 | Facebook | | 0 |
| 2 | Instagram | 1 | 1 |
| 3 | Whatsapp | 1 | 1 |
| 4 | Dynamic | 2 | 2 |
| 5 | Google | | 0 |
[
{
"organization_id": 1
"ogranization_name": "Facebook",
"childs": [
{
"organization_id": 2,
"ogranization_name": "Instagram",
"childs": null
},
{
"organization_id": 3,
"ogranization_name": "Whatsapp",
"childs": [
{
"organization_id": 4,
"ogranization_name": "Dynamic",
"childs": null
}
]
}
]
},
{
"organization_id": 5
"ogranization_name": "Google",
"childs": null
}
]
Answer the question
In order to leave comments, you need to log in
Ready packages? Yes, encoding/json. Hierarchical structures are the same as regular ones.
https://play.golang.org/p/SUE3lLBciMQ
PS The JSON you provided is invalid. There are two commas missing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question