JSON guide · 5 min read
How to Format and Pretty-Print JSON
Pretty-print compact JSON, choose indentation and safely format payloads without changing their data.
What pretty-printing does
Pretty-printing parses JSON and writes it again with line breaks and indentation. It improves readability but does not change the underlying values or object hierarchy.
Formatting versus minifying
Formatting adds whitespace for people. Minifying removes unnecessary whitespace to reduce payload size. Both representations describe the same JSON data when the transformation is successful.
Format JSON in the browser
Paste or open the payload in the JSON Formatter, validate it, and then copy or download the formatted result. Browser-local processing is useful when the document contains data you do not want uploaded to a remote service.
Format JSON with JavaScript
JSON.parse converts text into a JavaScript value and JSON.stringify writes it with indentation. The third argument controls the number of spaces.
const value = JSON.parse(rawJson);
const formatted = JSON.stringify(value, null, 2);When formatting fails
A formatter must parse the input first. If formatting fails, validate the syntax and fix errors such as trailing commas, missing quotes or incomplete objects before trying again.
Common questions
Frequently asked questions
Does formatting JSON change its values?
Normal formatting changes only whitespace. However, parsing and serializing may normalize number or escape representations, so important outputs should still be reviewed.
Should production JSON be minified?
Minification can reduce transfer size, although HTTP compression often provides a larger benefit. Readability may be preferable for configuration files and debugging artifacts.