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 Top answer 1 of 15
745
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>
2 of 15
45
Make sure the JSON output is in a <pre> tag.
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 ...
Call +917738666252
Address Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Videos
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);
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.
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
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 › @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.