Pretty-printing is implemented natively in JSON.stringify(). The third argument enables pretty printing and sets the spacing to use:

var str = JSON.stringify(obj, null, 2); // spacing level = 2

If you need syntax highlighting, you might use some regex magic like so:

function syntaxHighlight(json) {
    if (typeof json != 'string') {
         json = JSON.stringify(json, undefined, 2);
    }
    json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
        var cls = 'number';
        if (/^"/.test(match)) {
            if (/:$/.test(match)) {
                cls = 'key';
            } else {
                cls = 'string';
            }
        } else if (/true|false/.test(match)) {
            cls = 'boolean';
        } else if (/null/.test(match)) {
            cls = 'null';
        }
        return '<span class="' + cls + '">' + match + '</span>';
    });
}

See in action here: jsfiddle

Or a full snippet provided below:

function output(inp) {
    document.body.appendChild(document.createElement('pre')).innerHTML = inp;
}

function syntaxHighlight(json) {
    json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
        var cls = 'number';
        if (/^"/.test(match)) {
            if (/:$/.test(match)) {
                cls = 'key';
            } else {
                cls = 'string';
            }
        } else if (/true|false/.test(match)) {
            cls = 'boolean';
        } else if (/null/.test(match)) {
            cls = 'null';
        }
        return '<span class="' + cls + '">' + match + '</span>';
    });
}

var obj = {a:1, 'b':'foo', c:[false,'false',null, 'null', {d:{e:1.3e5,f:'1.3e5'}}]};
var str = JSON.stringify(obj, undefined, 4);

output(str);
output(syntaxHighlight(str));
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }

Answer from user123444555621 on Stack Overflow
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-stringify-online
JSON Stringify Online using JSON.Stringify()
JSON Stringify Online is very unique tool for convert JOSN to String and allows to download, save, share and print JSON to TSV data..
๐ŸŒ
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 - Yes, you can prettify your JSON instantly using an online tool like the JSON Beautifier from Fakerbox. It formats and structures messy JSON, highlights syntax, and helps in debugging, without manually using JSON.stringify().
Top answer
1 of 16
6932

Pretty-printing is implemented natively in JSON.stringify(). The third argument enables pretty printing and sets the spacing to use:

var str = JSON.stringify(obj, null, 2); // spacing level = 2

If you need syntax highlighting, you might use some regex magic like so:

function syntaxHighlight(json) {
    if (typeof json != 'string') {
         json = JSON.stringify(json, undefined, 2);
    }
    json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
        var cls = 'number';
        if (/^"/.test(match)) {
            if (/:$/.test(match)) {
                cls = 'key';
            } else {
                cls = 'string';
            }
        } else if (/true|false/.test(match)) {
            cls = 'boolean';
        } else if (/null/.test(match)) {
            cls = 'null';
        }
        return '<span class="' + cls + '">' + match + '</span>';
    });
}

See in action here: jsfiddle

Or a full snippet provided below:

function output(inp) {
    document.body.appendChild(document.createElement('pre')).innerHTML = inp;
}

function syntaxHighlight(json) {
    json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
        var cls = 'number';
        if (/^"/.test(match)) {
            if (/:$/.test(match)) {
                cls = 'key';
            } else {
                cls = 'string';
            }
        } else if (/true|false/.test(match)) {
            cls = 'boolean';
        } else if (/null/.test(match)) {
            cls = 'null';
        }
        return '<span class="' + cls + '">' + match + '</span>';
    });
}

var obj = {a:1, 'b':'foo', c:[false,'false',null, 'null', {d:{e:1.3e5,f:'1.3e5'}}]};
var str = JSON.stringify(obj, undefined, 4);

output(str);
output(syntaxHighlight(str));
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }

2 of 16
441

User Pumbaa80's answer is great if you have an object you want pretty printed. If you're starting from a valid JSON string that you want to pretty printed, you need to convert it to an object first:

var jsonString = '{"some":"json"}';
var jsonPretty = JSON.stringify(JSON.parse(jsonString),null,2);  

This builds a JSON object from the string, and then converts it back to a string using JSON stringify's pretty print.

๐ŸŒ
Code Beautify
codebeautify.org โ€บ json-stringify-online
JSON Stringify Online using JSON.stringify()
Json_Encode() Pretty Print using PHP ยท JSON to CSV Python ยท Python JSON ยท JSON Cheat Sheet ยท JSON Example ยท { "InsuranceCompanies": { "source": "investopedia.com" } } Result of JSON.Stringify() "{\r\n\"InsuranceCompanies\": {\r\n \"source\": \"investopedia.com\"\r\n }\r\n} " For Advanced Users ยท Load External URL in Browser URL like this https://codebeautify.org/ json-stringify-online?url=external-url ยท
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ JSON โ€บ stringify
JSON.stringify() - JavaScript | MDN
The JSON.stringify() static method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
๐ŸŒ
JSON Formatter
jsonformatter.org
Best JSON Formatter and JSON Validator: Online JSON Formatter
This JSON online formatter can also work as JSON Lint. Use Auto switch to turn auto update on or off for beautification. It uses $.parseJSON and JSON.stringify to beautify JSON easy for a human to read and analyze.
๐ŸŒ
Online Text Tools
onlinetexttools.com โ€บ json-stringify-text
JSON Stringify Text โ€“ Online Text Tools
Super simple, free and fast browser-based utility for JSON stringifying text. Just paste your text and it'll instantly get stringified. Textabulous!
Find elsewhere
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ json-formatter.html
Free Online JSON Formatter - FreeFormatter.com
<script> // A valid json string var someObject = {}; someObject.someProperty = "someValue"; // jsonString now contains a JSON string representation of someObject var jsonString = JSON.stringify(someObject); // Will display the string '{"someProperty":"someValue"}' alert(jsonString); </script>
๐ŸŒ
JSON Formatter
jsonformatter.curiousconcept.com
JSON Formatter & Validator
In order to keep focused on providing the best JSON beautifier and validator online, we do not offer an offline version.
๐ŸŒ
JSONLint
jsonlint.com โ€บ json-stringify
JSON Stringify - Escape JSON for Embedding | JSONLint | JSONLint
Convert JSON to an escaped string for embedding in code, databases, or other JSON. Handles quotes, newlines, and special characters.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ ounkkzpp โ€บ javascript-pretty-print-json-example
How do I pretty print JSON in JavaScript?
In this JavaScript Pretty Print JSON example, we use the JSON.stringify() method to print a JavaScript object in a human-readable format. Click Execute to run the JavaScript Pretty Print JSON example online ...
๐ŸŒ
W3Resource
w3resource.com โ€บ JSON โ€บ snippets โ€บ json-stringify-pretty.php
JSON.stringify for Pretty Print
JSON.stringify(person, null, "--"); This will use "--" as the indentation string. ... 1. Improves Readability: Pretty-printed JSON is easier to read and understand, especially for complex or nested data structures.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_stringify.asp
JSON.stringify()
You can convert any JavaScript datatype into a string with JSON.stringify().
๐ŸŒ
Online Tools
onlinetools.com โ€บ json โ€บ stringify-json
Stringify JSON โ€“ Online JSON Tools
Simple, free, and easy-to-use online tool that stringifies JSON. Just upload your JSON here and you'll instantly get a stringified JSON.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
CodeBeautify
codebeautify.org โ€บ jsonviewer
Best JSON Viewer and JSON Beautifier Online
Once you have created JSON Data, you can download it as a file or save it as a link and Share it. JSON Viewer works well on Windows, MAC, Chrome, and Firefox. JSON Pretty Print / Pretty JSON Tool to Prettify JSON data.
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 45-pretty-json-output
Pretty JSON Output | SamanthaMing.com
Tired of the one-liner JSON output, well no more! Utilize JSON.stringify built-in pretty printing.