how do i create nested Json object from flat object. if hod and dep code is same for different objects then add in same nested object. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// my flat object is ==>>
flatObj = [
{
hod : '1000',
dep : '2',
teacher : 'avi',
teacherno : '121',
teacheradd : 'mumbai',
teacheraddno : '133',
billtoname : 'manisha',
billtono : '77',
payname : 'mann',
payno : '99'
},
{
hod : '1567',
dep : '2',
teacher : 'shetty',
teacherno : '166',
teacheradd : 'gujrat',
teacheraddno : '190',
billtoname : 'annu',
billtono : '87',
payname : 'kiru',
payno : '495'
},
{
hod : '1567',
dep : '2',
teacher : 'shetty',
teacherno : '166',
teacheradd : 'gujrat',
teacheraddno : '190',
billtoname : 'raina',
billtono : '03',
payname : 'kiru',
payno : '495'
},
{
hod : '1000',
dep : '2',
teacher : 'kisha',
teacherno : '654',
teacheradd : 'pune',
teacheraddno : '986',
billtoname : 'kittu',
billtono : '576',
payname : 'hayat',
payno : '96'
}
];
and i want my nested object like
nestedObj = [
{
hod : '1000',
dep : '2',
teacherArr : [
{
teacher : 'avi',
teacherno : '121',
teacheraddArr : [
{
teacheradd : 'mumbai',
teacheraddno : '133',
billtoArr : [
{
billtoname : 'manisha',
billtono : '77',
payerArr : [
{
payname : 'mann',
payno : '99'
}
]
}
]
}
]
},
{
teacher : 'kisha',
teacherno : '654',
teacheraddArr : [
{
teacheradd : 'pune',
teacheraddno : '986',
billtoArr : [
{
billtoname : 'kittu',
billtono : '576',
payerArr : [
{
payname : 'hayat',
payno : '96'
}
]
}
]
}
]
}
]
},
{
hod : '1567',
dep : '2',
teacherArr : [
{
teacher : 'shetty',
teacherno : '166',
teacheraddArr : [
{
teacheradd : 'gujrat',
teacheraddno : '190',
billtoArr : [
{
billtoname : 'annu',
billtono : '87',
payerArr : [
{
payname : 'kiru',
payno : '495'
}
]
},
{
billtoname : 'raina',
billtono : '03',
payerArr : [
{
payname : 'kiru',
payno : '495'
}
]
}
]
}
]
}
]
}
];