Data:
var data = [ { \"id\": 1, \"level\": \"1\", \"text\": \"Sammy\", \"type\": \"Item\", \"items\": [
I needed to do the same thing, and while solving my issue found a solution to yours using lodash:
function kids(node) { return node.items ? [{...node, items: []}, _.map(node.items, kids)] : {...node, items: null}; } _.flatMapDeep(data, kids);