JSON.stringify() has pretty printing built in! console.log(JSON.stringify(o, null, 2)); Learnt this here.