Given these 4 variables,
var el1 = {name:'ronaldo', team: 'europe/spain/realmadrid'}
var el2 = {name:'messi', team: 'europe/spain/barcelona'}
var el3 = {name:'gerald', team: 'europe/england/liverpool'}
var el4 = {name:'unknown english', team: 'europe/england'}
I need to produce this JSON tree hierarchy,
{
"text":"europe",
"leaf":false,
"children":[
{
"text":"spain",
"leaf":false,
"children":[
{
"text":"realmadrid",
"leaf":false,
"children":[
{
"text":"ronaldo",
"leaf":true
}
]
},
{
"text":"barcelona",
"leaf":false,
"children":[
{
"text":"messi",
"leaf":true
}
]
}
]
},
{
"text":"england",
"leaf":false,
"children":[
{
"text":"unknown english",
"leaf":true
},
{
"text":"liverpool",
"leaf":false,
"children":[
{
"text":"gerald",
"leaf":true
}
]
}
]
}
]
}