Avatar ·

How to pretty-print JSON in JavaScript: readable format with indentation

Hello everyone! I'm a beginner in JavaScript and working with APIs that return data in JSON format. When I output an object using `console.log()`, it displays in a single line, which is very inconvenient to read, especially if the object is large and nested.\n\nHere's an example of my code:\n\n```javascript\nconst data = {\n name: "Ivan",\n age: 30,\n address: {\n city: "Moscow",\n street: "Tverskaya",\n zip: 101000\n },\n hobbies: ["programming", "reading", "sports"]\n};\n\nconsole.log(data);\n```\n\nIn the console I see something like: `{name: "Ivan", age: 30, address: {city: "Moscow", street: "Tverskaya", zip: 101000}, hobbies: ["programming", "reading", "sports"]}`. This is unreadable!\n\nI tried using `JSON.stringify()`, but the result still outputs in a single line. I need the JSON to be