I have json data of supervisor to supervisee. I need to get it into a nested form to use lib_ggOrgChart. The issue is.... it is very difficult! Struggling to see a straightforward way to do this. Maybe recursion or something... Anyone have any ideas?
I know I can write some brute force code... but I'm hoping for a more elegant solution. Any help appretiated!
{
{"Supervisor_ID": 1, "Supervisee_ID": 2},
{"Supervisor_ID": 1, "Supervisee_ID": 3},
{"Supervisor_ID": 1, "Supervisee_ID": 4},
{"Supervisor_ID": 2, "Supervisee_ID": 5},
{"Supervisor_ID": 3, "Supervisee_ID": 6},
{"Supervisor_ID": 4, "Supervisee_ID": 7},
{"Supervisor_ID": 4, "Supervisee_ID": 8},
{"Supervisor_ID": 4, "Supervisee_ID": 9}
}
I need to get it into this form:
{
'root':{
'id': 1,
'children': {
{
'id': 2,
'children': {
{
'id': 5
}
}
},
{
'id': 3,
'children': {
{
'id': 6
}
}
},
{
'id': 4,
'children': {
{
'id': 7
},
{
'id': 8
},
{
'id': 9
}
}
}
}
}