“I’m setting up a File browser and saving folder's name in database. Any number of folders can able to save in database, from the saved data i want to create a json tree.
This is my database table structure
folder_id folder_name parent_id
1 parentFolder1 <NULL>
2 parentFolder2 <NULL>
3 subFolder1 1
4 subFolder2 1
5 subFolder3 3
6 subFolder4 2
7 subFolder5 5
parent_id is a foreign key which refer folder_id.
This is the json tree structure am trying to create from the above database and more parent folder and subfolders will be add in future. if it is possible create json tree from the the above table structure? can any one please help me?
[
{
"id": "1",
"value": "parentFolder1",
"data": [
{
"id": "3",
"value": "subFolder1",
"data": [
{
"id": "5",
"value": "subFolder3",
"data": [
{
"id": "7",
"value": "subFolder5",
"data": []
]
}
]
}
},
{
"id": "4",
"value": "subFolder2",
"data": []
}
]
},
{
"id": "2",
"value": "parentFolder2",
"data": [
{
"id": "6",
"value": "subFolder4",
"data": []
}
]
}
]