function nest(data, keys) {
if (!keys.length) return data;
const [first, ...rest] = keys;
return Object.values(data.reduce((acc, row) => {
const key = row[first];
if (!acc[key]) {
acc[key] = { name: key, children: [] };
}
acc[key].children.push(rest.length ? row : {...row, name: row.Item});
return acc;
}, {}));
}