Table for my folder structure
id | name | parent_id
----+--------------+-----------
1 | parent |
2 | child | 1
3 | grandchild A | 2
4 | grandchild B | 2
5 | grandchild c | 3
select id,parent_id, name from table.
I want to create a json
for this result set which should be in tree structure.
how to make a json for this,
please help.
I guess I would structure the tree like this (with id's where appropriate):
What is your data structure inside of Node that you need to transform? If this is in a DB table, then how are you getting it into node and what does it look like once it is there - you could console.log(JSON.stringify(object, null 4)) to output the current structure