I would like to generate tree structure from following data:
[
{"first_name" => "Test", "id" => "1", "parent_id" => ""},
{"first_name" => "Test1", "id" => "2", "parent_id" => "1"},
{"first_name" => "Test2", "id" => "3", "parent_id" => "1"},
{"first_name" => "Test3", "id" => "4", "parent_id" => "2"}
]
I would like to create ruby script to build following structure:
[
{
"first_name" => "Test",
"id" => "1",
"children" => [
{
"first_name" => "Test1",
"id" => "2",
"children" => [
{
"first_name" => "Test3",
"id" => "4"
}
]
},
{
"first_name" => "Test2",
"id" => "3"
}
}
]
Do you have some tips in this case?