const depth = (n) => { if (n > 1) { return { children: { include: depth(n - 1), }, }; } else { return { children: true, }; } }; console.log(JSON.stringify(depth(1000))); //console.log(JSON.stringify(depth(2))) //console.log(JSON.stringify(depth(3))) //console.log(JSON.stringify(depth(4)))