why are you adding whole headers to the stack, when you only need sections? I'd change those line to
stack[stack.length - 1].push(obj);
stack.push(obj.sections);