📋
JSON Formatter
⭐ Featured textPretty-print, minify or validate JSON and see its key count, array count, nesting depth and size before and after.
Use the Tool
Generated Palette
Click any color to copy hex code
Generated Passwords
Formatted Output
Summary
Quick Tip Reference
| Tip % | Tip Amount | Total |
|---|---|---|
Amortization Schedule (first 12 months)
| Month | Payment | Principal | Interest | Balance |
|---|---|---|---|---|
All Conversions
About This Tool
The JSON Formatter takes a block of raw JSON and either pretty-prints it with a readable indent, minifies it down to the smallest valid form, or simply validates it. Alongside the reformatted output it reports a short structural summary: the number of keys, the number of arrays, the maximum nesting depth, and the byte size of the input compared with the byte size of the result. That combination is useful when you are handed an unfamiliar API response and need to understand its shape as well as read it. If the input is not valid JSON, the tool returns the parser's own error message, such as a syntax error or a depth limit, rather than failing silently. Indentation is configurable between two and eight spaces. Unicode characters and forward slashes are left unescaped in formatted output, so text stays readable rather than turning into escape sequences.
How the formatting and analysis work
The tool first parses the input with a strict JSON decoder. Parsing is the validation step: if the decoder reports any error, the input is rejected and the specific reason is returned, whether that is a syntax error, an unexpected end of data, malformed UTF-8 or exceeding the maximum nesting depth. Nothing is guessed at or repaired.
Once the text parses cleanly, the action you chose decides the output. Minify re-encodes the parsed structure with no whitespace at all, producing the smallest valid representation. Format re-encodes it pretty-printed, with Unicode left as readable characters and forward slashes unescaped rather than written as backslash-slash sequences. The default indent is four spaces; choosing anything from two to eight rescales the indentation of every line proportionally.
Because the output is regenerated from the parsed structure rather than edited as text, formatting also normalises the document. Inconsistent spacing, mixed indentation and stray line breaks all disappear. The structural summary is produced by walking the parsed value: counting object keys at every level, counting arrays, and tracking the deepest level of nesting reached. Sizes are reported in bytes for the original input and the generated output.
Once the text parses cleanly, the action you chose decides the output. Minify re-encodes the parsed structure with no whitespace at all, producing the smallest valid representation. Format re-encodes it pretty-printed, with Unicode left as readable characters and forward slashes unescaped rather than written as backslash-slash sequences. The default indent is four spaces; choosing anything from two to eight rescales the indentation of every line proportionally.
Because the output is regenerated from the parsed structure rather than edited as text, formatting also normalises the document. Inconsistent spacing, mixed indentation and stray line breaks all disappear. The structural summary is produced by walking the parsed value: counting object keys at every level, counting arrays, and tracking the deepest level of nesting reached. Sizes are reported in bytes for the original input and the generated output.
Worked example: a minified API response
Take the input {"user":{"id":42,"name":"Ada","roles":["admin","editor"],"meta":{"active":true}}} on a single line. It parses cleanly, so the status is reported as valid.
Formatted at four spaces, it becomes a nested block: the outer brace on line one, "user" indented by four, its four properties indented by eight, the two role strings indented by twelve inside their array, and "active" indented by twelve inside the meta object.
The structural summary counts six keys in total: user, id, name, roles, meta and active. It counts one array, the roles list. The maximum depth is four, since reaching the value true means descending through the root object, user, meta and then the key itself. Raw size is 88 bytes, while the formatted version is larger because of the added newlines and leading spaces.
Switching to minify on the already-formatted version returns it to the original single line at 88 bytes, confirming that the two operations are reversible and that no data is altered in either direction.
Formatted at four spaces, it becomes a nested block: the outer brace on line one, "user" indented by four, its four properties indented by eight, the two role strings indented by twelve inside their array, and "active" indented by twelve inside the meta object.
The structural summary counts six keys in total: user, id, name, roles, meta and active. It counts one array, the roles list. The maximum depth is four, since reaching the value true means descending through the root object, user, meta and then the key itself. Raw size is 88 bytes, while the formatted version is larger because of the added newlines and leading spaces.
Switching to minify on the already-formatted version returns it to the original single line at 88 bytes, confirming that the two operations are reversible and that no data is altered in either direction.
Fixing invalid JSON and reading the statistics
When validation fails, read the error message first. Syntax error is by far the most common and usually means a trailing comma after the last item in an object or array, single quotes used instead of double quotes, unquoted property names, or a stray comment. None of these are legal JSON even though JavaScript accepts several of them. Control character error points to a literal newline or tab inside a string value, which must be escaped as backslash-n or backslash-t.
Depth limit exceeded indicates deeply recursive data rather than a typo. Malformed UTF-8 usually means a legacy encoding or a file truncated mid-character.
The statistics are worth a glance even when the JSON is valid. A high depth figure, say six or more, often signals a response that will be painful to consume and might be worth flattening. Comparing raw size against minified size shows exactly what you save by stripping whitespace before sending a payload over the wire.
One caution: pretty-printing regenerates the document, so key order is preserved but formatting choices you made by hand are not. Avoid pasting production secrets, tokens or personal data into any online formatter as a matter of routine.
Depth limit exceeded indicates deeply recursive data rather than a typo. Malformed UTF-8 usually means a legacy encoding or a file truncated mid-character.
The statistics are worth a glance even when the JSON is valid. A high depth figure, say six or more, often signals a response that will be painful to consume and might be worth flattening. Comparing raw size against minified size shows exactly what you save by stripping whitespace before sending a payload over the wire.
One caution: pretty-printing regenerates the document, so key order is preserved but formatting choices you made by hand are not. Avoid pasting production secrets, tokens or personal data into any online formatter as a matter of routine.
Frequently Asked Questions
Usually a trailing comma after the final element, single quotes instead of double quotes, or unquoted property names. JavaScript object literals permit all three but JSON does not. Comments are also invalid in standard JSON. The tool reports the parser's exact message so you can narrow down which rule was broken.
Formatting adds newlines and indentation so a human can read the structure; minifying removes every optional whitespace character to make the payload as small as possible for transmission or storage. Both produce identical data, just different text, and you can convert freely between them without losing anything.
Two spaces is the most widely used convention in JavaScript and TypeScript projects, while four is common elsewhere and is the default here. You can choose anything from two to eight. The choice is cosmetic and affects only file size and readability, never how the JSON is parsed.
It is the deepest level of nesting in the document, counting each object or array you must descend through to reach the innermost value. A flat object is depth one or two; a response at depth six or more is typically awkward to work with and may be worth restructuring before other code has to consume it.
No. The document is parsed and re-encoded, so values and key order are preserved exactly. Only whitespace changes. Formatted output additionally leaves Unicode characters and forward slashes unescaped, which makes text more readable without altering what the JSON means to a parser.
Category
💻Developer Tools
Browse category
Statistics
Views
441
Uses
958
Type
text