(function toArrays(obj) {
const arr = Object.values(obj ?? {});
arr.forEach(n => n.children = toArrays(n.children));
return arr;
})(arr.reduce((acc, n) => {
const path = n.path.replace(/^\/|\/$/g, '').split('/');
const obj = path.reduce((p, c) => ((p.children ??= {})[c] ??= {}), acc);
Object.assign(obj, n);
return acc;
}, {}).children)