Thank you in advance for the help!
I'm attempting to convert a specific javascript map into a nested JSON object. A sample of the map looks like:
["a", ["b", "c"]]
["b", ["e"]]
["c", ["f"]]
["e", []]
["f", []]
where the key represents a parent node, and the values in the arrays are its direct children. Empty arrays for values indicates no children for that given key. I would like to generate an output that looks like:
{
"name": “a”,
"children": [{
"name": “b”,
"children": [{
"name": “e”
}]
}, {
"name": “c”,
"children": [{
"name": “f”,
}]
}]
}
(this may not be a well-formed json object as typed, but hopefully is illustrative of the hierarchical relationship the javascript example map is demonstrating). Additionally, though trivial, the keys nor the values in the arrays are assumed to be sorted.
Lastly, I know this lends itself to a recursive solution. Any help would be immensely appreciated. Thank you again for the time!