Format and pretty-print JSON online
What an online JSON formatter and validator changes, when pretty-printed output is equivalent to the original, and when to keep compact or original JSON.
Pretty-printing JSON adds line breaks and indentation so that the nesting of objects and arrays is easy to see. Most online formatters and validators do two jobs. First, they check whether the text parses as JSON. Second, they rewrite it in a readable layout. This review covers what that rewrite changes, what it should leave alone, and when you should keep the compact or original version instead.
Short verdict: is pretty-printing right for your use?
Pretty-printing suits reading, debugging, reviewing API responses, and comparing configuration files. Its main benefit is that structure becomes visible: you can see where an object ends, which keys belong to which level, and where a syntax error sits. The decisive tradeoff is that many formatters parse the data and then serialize it again. The result is a new rendering of the data, not your original bytes. In ordinary cases it means the same thing, but in some edge cases it does not. Keep the original or minified text in these situations: when exact bytes matter (signatures, hashes, checksums), when the format requires one record per line, when payload size matters, or when the data is sensitive and you cannot confirm how the tool handles your input.
What pretty-printing actually changes
The JSON grammar allows insignificant whitespace (spaces, tabs, line feeds, carriage returns) around structural characters such as braces, brackets, colons and commas. Adding or removing that whitespace does not change the data. Whitespace inside a string value is different: it is part of the value, and a correct formatter leaves it untouched.
Input (minified):
{"user":{"name":"Ada Lovelace","roles":["admin","editor"],"active":true}}
Output (two-space indentation):
{
"user": {
"name": "Ada Lovelace",
"roles": [
"admin",
"editor"
],
"active": true
}
}
In this example the keys, values and key order are identical. Only the whitespace between tokens differs. The space inside "Ada Lovelace" is preserved because it belongs to the string. This is a stored-character change: real newline and space characters are added to the text. It is not a visual effect. Pretty-printing has nothing to do with fonts or styled Unicode characters. Some tools also show syntax colouring, line numbers or a collapsible tree. Those are presentation on the web page, separate from the text you copy.
Format, beautify, minify, validate: what each term means
- Format, beautify and pretty-print all mean the same thing: add indentation and line breaks for readability.
- Minify means the reverse: remove insignificant whitespace to make the text compact.
- Validate usually means checking that the text is well-formed JSON according to the grammar.
- Schema validation is a separate step. It checks the data against a JSON Schema: required fields, types, allowed values. A formatter reporting "valid JSON" normally means only that the text is well-formed, not that it matches any schema.
When the output is not a byte-for-byte equivalent
Formatters that parse into memory and then serialize again inherit the rules of their parser. Browser-based tools often rely on JavaScript's built-in JSON.parse and JSON.stringify. Those functions have the following documented behaviours:
- Large integers lose precision. Numbers are stored as double-precision floats, so integers above 2^53 may change. For example, 9007199254740993 becomes 9007199254740992. This matters for IDs generated by some databases and APIs.
- Number spelling is normalised. 1.0 becomes 1, and 1e2 becomes 100. The numeric value is the same, but the text differs.
- Duplicate keys collapse to one. Only the last value is kept. The JSON specification says object names should be unique and warns that behaviour with duplicates is unpredictable across implementations.
- Key order can shift. Keys that look like non-negative integers are moved to the front in ascending order, ahead of other keys.
- Escapes are rewritten. \u00e9 is output as é, and / is output as /. The string value is the same, but the bytes differ.
Input:
{"b":1,"2":"x","id":9007199254740993,"price":1.0,"name":"Caf\u00e9"}
Output from JSON.parse followed by JSON.stringify with two-space indentation:
{
"2": "x",
"b": 1,
"id": 9007199254740992,
"price": 1,
"name": "Café"
}
Not every formatter works this way. Some re-indent the original tokens without converting numbers or strings, and those preserve the source text. No documentation or test results for specific online formatters were available for this review, so it does not say which tools behave which way. If accuracy matters, test the tool yourself. Paste a small sample that contains a large integer, a duplicate key, a numeric-looking key and an escaped character, then compare the output with the input.
What a validator will and will not accept
Strict JSON does not allow comments, trailing commas, single-quoted strings, unquoted keys, or the values NaN and Infinity. Configuration files written in lenient dialects such as JSONC or JSON5 can therefore fail a strict validator and still be correct for the program that reads them. Some formatters accept lenient input and return strict JSON, which silently drops comments. If your file has comments you need, check whether they survive. Error locations also deserve a careful read. A missing comma is often reported at the next token, not at the place where the comma belongs, so look just before the reported position too.
Copying, sharing and editing the result
Pretty-printed JSON is plain text, so it pastes cleanly into code editors and terminals. Rich-text destinations can be less reliable. Some editors collapse leading spaces, wrap long lines, or turn straight quotes into curly quotes, and curly quotes make the JSON invalid. Where the destination offers a code block or preformatted option, use it. Before relying on a shared copy, check it once in the actual destination; one clean paste elsewhere does not prove it will work everywhere. When copying from a page with highlighting or line numbers, confirm that the line numbers did not come along with the text.
- Indentation style: two spaces, four spaces and tabs are all valid. Match your project's convention so that diffs show real changes rather than whitespace noise.
- Size: indentation adds characters. That is fine for reading, but minify for network transport or storage where size counts.
- Line-delimited formats: JSON Lines and NDJSON require each record on a single line. Pretty-printing such a file breaks the format.
- Signed or hashed payloads: any change in bytes, including whitespace, changes a hash or invalidates a signature computed over the original text. Keep the original exactly as received.
- Search: a search that spans a key and its value, such as "status":"ok", may miss matches once a space is inserted after the colon. Adjust the pattern, or search the parsed data with a query tool instead.
Accessibility considerations
Indentation lets sighted readers see nesting at a glance. Syntax colours can help as well, but they should not be the only cue, because some readers cannot distinguish them. For screen reader users, whether indentation is announced depends on the screen reader and its settings. No scoped test with any specific assistive technology was available, so this review makes no claim about how a particular one reads formatted JSON. Collapsible tree views on web pages may or may not work by keyboard and with screen readers. A plain-text copy opened in an editor the reader already controls is a dependable fallback.
Privacy: check before you paste
JSON from real systems often contains access tokens, API keys or personal data. A clean interface or a claim that processing is secure does not tell you whether the data stays in your browser or is sent to a server, or whether it is logged or kept. No privacy or retention information about specific tools was available for this review. Rely on a tool's documented policy. For sensitive data, format locally instead: most code editors include a format command, and command-line tools can do the same job.
python3 -m json.tool input.json
jq . input.json
These local tools also parse and re-serialize, each with its own rules for numbers, escapes and duplicate keys. Check their documentation for the version you have installed if exact preservation matters.
Quick checklist
- Use pretty-printed JSON for reading, debugging, code review and documentation.
- Keep the original bytes for signatures, hashes and anything you will compare byte-for-byte.
- Keep one record per line for JSON Lines or NDJSON.
- Test unfamiliar formatters with large integers, duplicate keys, numeric-looking keys and escaped characters.
- Treat "valid" as well-formed only, unless the tool also checks a schema.
- Paste into code blocks or plain-text fields to avoid curly quotes and collapsed spaces.
- Format sensitive data locally unless the online tool's handling of your data is documented.