function parse(input) {
const result = [];
const stack = [];
const lines = input.split("\n");
let indent = 0;
let col = result;
let item;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
let curInd = 0;
while (line[curInd] === " ") curInd++;
if (curInd > indent) {
stack.push({ indent, col });
col = item.children;
}
if (curInd < indent) {
let s;
do {
s = stack.pop();
} while (s.indent > curInd)
col = s.col;
}
indent = curInd;
item = {
description: line.substr(curInd),
children: []
};
col.push(item);
}
console.log(JSON.stringify(result, null, 2));
}