JSON.stringify takes more optional arguments.
Try:
JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, 4); // Indented 4 spaces
JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, "\t"); // Indented with tab
From:
How can I beautify JSON programmatically?
It should work in modern browsers, and it is included in json2.js if you need a fallback for browsers that don't support the JSON helper functions. For display purposes, put the output in a <pre> tag to get newlines to show.
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
Videos
02:38
JavaScript tips โ Pretty print json strings with JSON.stringify ...
05:56
JSON.stringify() Explained: The Ultimate Guide for Beginners - YouTube
How to Format & Display a Json in HTML + Javascript - YouTube
14:36
Why do we need JSON.stringify and parse? - YouTube
05:04
What is JSON.stringify in JavaScript | Convert JavaScript Objects ...
02:24
DevTips Daily: Format the output of JSON.stringify - YouTube
W3Schools
w3schools.com โบ js โบ js_json_stringify.asp
JSON.stringify()
Use the JavaScript function JSON.stringify() to convert it into a 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 - JSON.stringify() is definitely a helpful method for making JSON data more readable and organized. Additionally, it's important to note that JSON is widely used for data interchange between web services and applications, so having well-formatted JSON can also make it easier for different systems ...
Keyboard Maestro
forum.keyboardmaestro.com โบ tips & tutorials
TIP: How to Get Readable Format from JSON.stringify() - Tips & Tutorials - Keyboard Maestro Discourse
March 20, 2017 - TIP: How to Get Readable Format from JSON.stringify() I suspect most of you JavaScript and JavaScript for Automation (JXA) scripters are at least somewhat familiar with the powerful JSON functions, like JSON.stringify() - JavaScript | MDN. However, some of you, like me, may not be aware of some options of the JSON.stringify() function to generate a very readable output, and to filter the output.
ReqBin
reqbin.com โบ code โบ javascript โบ ounkkzpp โบ javascript-pretty-print-json-example
How do I pretty print JSON in JavaScript?
To make JSON readable, you need to generate a pretty JSON string. JavaScript has a built-in JSON.stringify(obj, replacer, space) method to convert objects to JSON and pretty-print the generated JSON string.
The Code Barbarian
thecodebarbarian.com โบ pretty-json-stringify-output.html
Pretty `JSON.stringify()` Output in JavaScript
This lets you format the JSON: const app = express(); app.use(express.text({ type: '*/*' })); app.post('*', (req, res) => { console.log(req.body); res.end(req.body); }); await app.listen(3000); // Make a test request const axios = require('axios'); const obj = { name: 'Jean-Luc Picard', rank: 'Captain', ship: 'Enterprise D' }; const res = await axios.post('http://localhost:3000', obj, { transformRequest: data => JSON.stringify(data, null, 2), // Send pretty formatted JSON transformResponse: body => body }); // { // "name": "Jean-Luc Picard", // "rank": "Captain", // "ship": "Enterprise D" // } console.log(res.data);
W3Schools
w3schools.com โบ jsref โบ jsref_stringify.asp
JavaScript JSON stringify() Method
/*replace the value of "city" to upper case:*/ var obj = { "name":"John", "age":"39", "city":"New York"}; var text = JSON.stringify(obj, function (key, value) { if (key == "city") { return value.toUpperCase(); } else { return value; } }); Try it Yourself ยป
4D
developer.4d.com โบ 4d language โบ commands by theme โบ json โบ json stringify
JSON Stringify | 4D Docs
This command performs the opposite action of the JSON Parse command. Pass the data to be serialized in value. It can be expressed in scalar form (string, number, date or time) or by means of a 4D object or collection. Note: 4D dates will be converted either in "yyyy-mm-dd" or "YYYY-MM-DDTh...
GeeksforGeeks
geeksforgeeks.org โบ javascript โบ how-to-pretty-print-json-string-in-javascript
How to Pretty Print JSON String in JavaScript? - GeeksforGeeks
July 12, 2025 - The JSON object to stringify. A replacer function (optional). The number of spaces for indentation (optional). ... By providing an indentation value, you can control the amount of spacing for nested elements. ... const data = { name: "Anjali", profession: "Developer", skills: ["JavaScript", "Python"] }; const formatted = JSON.stringify(data, null, 4); console.log(formatted);
GitHub
github.com โบ DJj123dj โบ formatted-json-stringify
GitHub - DJj123dj/formatted-json-stringify: An advanced & customisable version of the javascript JSON.stringify() function!
It's just a wrapper around the default JSON.stringify()! const input = { property1:"this is the first property", property2:"this is the second property", property3:123, subObject:{ sub_property_1:true, sub_property_2:false, sub_array:["abcd","efg","hijk","lmnop","qrst","uvw","xyz","and thats the alphabet!"] } } const formatter = new fjs.ObjectFormatter(null,true,[ new fjs.PropertyFormatter("property1"), new fjs.PropertyFormatter("property2"), new fjs.PropertyFormatter("property3"), new fjs.TextFormatter(), //we don't know the contents of this object //but we still want to render it multiline/inline new fjs.DefaultFormatter("subObject",true)
Author ย DJj123dj
DEV Community
dev.to โบ david_j_eddy โบ til-jsonstringify-can-do-formatted-output-1f44
TIL: JSON.stringify() can do formatted output. - DEV Community
December 18, 2017 - var obj = {name: "bob", lastname: "jones", age: 24, favouriteFood: "food", favouriteColour: "blue?", loves: "biscuits" }; JSON.stringify(obj, null, "two spaces"); "{ two spaces"name": "bob", two spaces"lastname": "jones", two spaces"age": 24, two spaces"favouriteFood": "food", two spaces"favouriteColour": "blue?", two spaces"loves": "biscuits" }"
GeeksforGeeks
geeksforgeeks.org โบ javascript โบ javascript-json-stringify-method
JavaScript JSON stringify() Method - GeeksforGeeks
July 11, 2025 - The JSON.stringify() method in JavaScript is used to convert JavaScript objects into a JSON string. This method takes a JavaScript object as input and returns a JSON-formatted string representing that object.