Please use a <pre> tag

demo : http://jsfiddle.net/K83cK/

var data = {
  "data": {
    "x": "1",
    "y": "1",
    "url": "http://url.com"
  },
  "event": "start",
  "show": 1,
  "id": 50
}


document.getElementById("json").textContent = JSON.stringify(data, undefined, 2);
<pre id="json"></pre>

Answer from Diode on Stack Overflow
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › json stringify pretty
JSON Stringify Pretty
April 12, 2023 - JSON Stringify Pretty helps to prettify JSON data and print it. ‘Pretty’ prettifies JSON content and ‘Print’ prints the prettified JSON content. PrettyPrint is an application that helps in converting various formats to text files or ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
If it is a number, successive levels in the stringification will each be indented by this many space characters. If it is a string, successive levels will be indented by this string. Each level of indentation will never be longer than 10. Number values of space are clamped to 10, and string values are truncated to 10 characters. ... JSON.stringify({}); // '{}' JSON.stringify(true); // 'true' JSON.stringify("foo"); // '"foo"' JSON.stringify([1, "false", false]); // '[1,"false",false]' JSON.stringify([NaN, null, Infinity]); // '[null,null,null]' JSON.stringify({ x: 5 }); // '{"x":5}' JSON.string
🌐
ServiceNow Community
servicenow.com › community › developer-articles › json-stringify-making-json-look-pretty-and-perfect › ta-p › 2534944
JSON.stringify() - Making JSON Look Pretty and Per... - ServiceNow Community
December 9, 2025 - So, how do we use JSON.stringify()? It's actually quite simple. All you need is your JSON object and the stringify() method. And if you want to make it look even prettier, just add null and '\t' as the second and third parameters.
🌐
W3Resource
w3resource.com › JSON › snippets › json-stringify-pretty.php
JSON.stringify for Pretty Print
// Define a nested JavaScript object const company = { name: "TechCorp", employees: [ { name: "Sara", role: "Developer" }, { name: "Emily", role: "Designer" } ], location: "New York" }; // Convert nested object to a JSON string with pretty print (4 spaces indentation) const jsonString = JSON.stringify(company, null, 4); // Output the pretty-printed JSON string console.log(jsonString);
🌐
The Code Barbarian
thecodebarbarian.com › pretty-json-stringify-output.html
Pretty `JSON.stringify()` Output in JavaScript
However, by default, JSON.stringify() outputs minified JSON, with no whitespace or colors.
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
Use the JavaScript function JSON.stringify() to convert it into a string. ... The result will be a string following the JSON notation.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-pretty-print-json-string-in-javascript
How to Pretty Print JSON String in JavaScript? - GeeksforGeeks
July 12, 2025 - To pretty print JSON, you can format JSON strings with proper indentation, making them easy to read and debug. In JavaScript, you can achieve this using JSON.stringify() with optional parameters to specify the indentation level.
Find elsewhere
🌐
GitHub
github.com › lydell › json-stringify-pretty-compact
GitHub - lydell/json-stringify-pretty-compact: The best of both `JSON.stringify(obj)` and `JSON.stringify(obj, null, indent)`. · GitHub
While the “pretty” mode of JSON.stringify puts every item of arrays and objects on its own line, this module puts the whole array or object on a single line, unless the line becomes too long (the default maximum is 80 characters).
Author   lydell
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-pretty-print-json-using-javascript.php
How to Pretty-print JSON Using JavaScript
// Sample object var obj = {"name": "Peter", "age": 22, "country": "United States"}; // Pretty printing var str = JSON.stringify(obj, null, 4); // spacing level = 4 console.log(str);
🌐
GitHub
github.com › dtjm › prettify › blob › master › json-pretty-print.html
prettify/json-pretty-print.html at master · dtjm/prettify
var jsonString = JSON.stringify(JSON.parse(textarea.value), null, " "); output.innerText = jsonString; errorElement.innerText = ""; } · · catch(error) { errorElement.innerText = error; } } · // http://www.JSON.org/json2.js ·
Author   dtjm
🌐
SamanthaMing
samanthaming.com › tidbits › 45-pretty-json-output
Pretty JSON Output | SamanthaMing.com
const protein = { steak: '🥩', bacon: '🥓' }; JSON.stringify(protein, null, 1); /* { "steak": "🥩", "bacon": "🥓" } */ Alternatively, you can use a string as your indentation. It allows a maximum of 10 characters. If you try to pass more than 10, it will just use the first 10 characters. So don't try to beat the system 😝 · const protein = { steak: '🥩', bacon: '🥓' }; JSON.stringify(protein, null, 'I 💛'); /* { I 💛"steak": "🥩", I 💛"bacon": "🥓" } */
🌐
ReqBin
reqbin.com › code › javascript › ounkkzpp › javascript-pretty-print-json-example
How do I pretty print JSON in JavaScript?
To pretty-print JSON in JavaScript, you can use the JSON.stringify(obj, replacer, space) method. The third parameter of the JSON.stringify() method specifies the number of spaces to use when outputting the JSON string.
🌐
ZetCode
zetcode.com › javascript › json-pretty-print
JavaScript JSON Pretty Print - Formatting JSON Data
We prettify the output with JSON.stringify. ... <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => document.body.appendChild(document.createElement('pre')).innerHTML = JSON.stringify(json, null, 4)); </script> </body> </html>
🌐
Stack Overflow
stackoverflow.com › questions › 4810841 › pretty-print-json-using-javascript
pretty-print JSON using JavaScript - Stack Overflow
all answer will work but you have to use javascript :: var str = JSON.stringify(obj, null, 2); in html // <pre id="output_result_div"></pre > ... Use JSON.stringify(data, null, 2) to format data, then use AceEditor, CodeMirror, or Monaco Editor ...
🌐
Medium
medium.com › coding-at-dawn › how-to-pretty-print-json-in-just-one-line-of-javascript-html-or-react-2e79edd2b7ee
How To Pretty Print JSON in Just One Line of JavaScript + HTML (or React) | by Dr. Derek Austin 🥳 | Coding at Dawn | Medium
January 6, 2023 - How To Pretty Print JSON in Just One Line of JavaScript + HTML (or React) Ever need to debug a giant JSON object while working on frontend development? I’ve got you covered. When you’re …
🌐
Delft Stack
delftstack.com › home › howto › javascript › json stringify pretty
How to Pretty Print JSON in JavaScript | Delft Stack
March 11, 2025 - One of the most straightforward ways to pretty print JSON in JavaScript is by using the JSON.stringify() method.
🌐
YouTube
youtube.com › shorts › dzhR4RTg13g
How to Format & Display a Json in HTML + Javascript - YouTube
July 22, 2023 - How to use pre tags and JSON.stringify to pretty print a JSON in HTML and the JavaScript console.⭐ Get my full-stack Next.js with Express & TypeScript course...
🌐
Medium
medium.com › @python-javascript-php-html-css › how-to-display-json-in-a-readable-format-using-javascript-34d95031a42a
How to Use JavaScript to Display JSON in a Readable Format
August 24, 2024 - In this article, we will explore various techniques to pretty-print JSON using JavaScript. Whether you’re a developer debugging an API response or simply need to present data more clearly, these methods will help you achieve a human-friendly JSON display. ... In the first script, we use JavaScript to format and display JSON in a more readable manner. The function syntaxHighlight takes a JSON object as input and converts it to a string with JSON.stringify, applying a 4-space indentation.