I have a tree structure that I need to convert into JSON format for use with a jquery option tree.
NodeId, Title, Level
1, cars, 0
2, boats, 0
3, oldtimer, 1
4, trucks, 1
5, heavytrucks, 4
The desired tree structure is as follows:
boats
cars
- oldtimer
- trucks
-- heavytrucks
Each item within the tree has an ID associated with it.
Can someone please advise on how I can efficiently convert this structure into JSON?
Below is an example of the expected output in the jquery option tree format:
var option_tree = {
"Option 1": {
"Suboption": 200
},
"Option 2": {
"Suboption 2": {
"Subsub 1": 201,
"Subsub 2": 202
},
"Suboption 3": {
"Subsub 3": 203,
"Subsub 4": 204,
"Subsub 5": 205
}
}
};
Please note that `Option 1` does not have its own ID, but rather child elements only.