JSON Formatter

Format, validate and minify JSON in your browser. Errors include line numbers so you can fix broken JSON fast.

Loading tool…

How It Works

The formatter runs a two-step pipeline in your browser. Step one parses your input with JSON.parse — the same parser JavaScript itself uses — so acceptance exactly matches the language runtime: nothing stricter, nothing looser. Step two re-serializes the parsed value with JSON.stringify at two-space indentation, which normalizes spacing, line breaks and key layout without touching your data.

Because output is derived from the parsed value, only whitespace is rewritten. String contents, numbers, booleans, null and the order in which keys first appear all survive. Unicode text and escape sequences such as \n and \t round-trip cleanly, so a document full of Chinese keys or tabbed strings reformats without corruption.

When parsing fails, the tool keeps the engine's error message and converts the character position inside it into a line number, so an "Unexpected token" points at the offending line instead of a raw byte offset. Chrome and Firefox phrase parse errors differently — Firefox reports a position rather than a line — and the page normalizes both into a line number before display.

Empty or whitespace-only input is reported as an "Empty input" error rather than formatted as an empty document. That is deliberate: an empty result after a format attempt usually means a failed paste, and a silent success would hide it.

How to format a JSON document

  1. Paste the JSON into the input box — the tool parses it immediately.
  2. Valid documents come back re-indented at two spaces, ready to copy.
  3. If parsing fails, read the error: it names the problem and the line to fix.
  4. Correct that line in your source, paste again, and repeat until the document formats cleanly.

Common reasons JSON.parse rejects input

Input patternWhy it failsFix
{"a":1,}Trailing comma before the closing braceDelete the comma
{a:1}Key is not wrapped in double quotesQuote the key
{name: "ok"}Single quotes are not valid JSONUse double quotes
{"n":1 // count}JSON has no comment syntaxRemove the comment

Examples

Input

{"b":2,"a":1}

Output

{
  "b": 2,
  "a": 1
}

Compact JSON is re-indented with two spaces; key order is preserved.

Input

{"中文":"值"}

Output

{
  "中文": "值"
}

Unicode keys and values round-trip without escaping or corruption.

Input

{"a":1,}

Output

SyntaxError: Unexpected token } (line 1)

Boundary: a trailing comma is rejected and reported with its line number.

Input

Output

Empty input

Boundary: empty input is an error, not an empty document.

Frequently Asked Questions

What is the difference between formatting and validating?
Formatting re-indents JSON that already parses; validation is what happens automatically on every paste. If the syntax is broken you get an error with a line number, and if it is valid you get the formatted document back. Both outcomes tell you the JSON is valid — only the output differs.
Why is my JSON rejected even though it looks fine?
The most common causes are trailing commas before a closing brace, single quotes around keys or strings, comments (JSON allows none), and unquoted keys. All are valid in JavaScript object literals but not in strict JSON, which is what APIs exchange.
Does the formatter change or sort my values?
No. Only whitespace is rewritten. Strings, numbers and booleans are preserved exactly, and keys stay in the order they appeared in your input — the tool never alphabetizes or reorders anything.
What happens to very large integers?
JSON numbers become JavaScript doubles, so integers beyond Number.MAX_SAFE_INTEGER (9,007,199,254,740,991) silently lose precision. Treat such fields as strings if their exact value matters.

Limitations & Accuracy

Strict RFC 8259 JSON only: comments, trailing commas, single quotes and unquoted keys are rejected. Numbers are JavaScript doubles, so integers beyond Number.MAX_SAFE_INTEGER lose precision. Error line numbers depend on the engine message — Chrome reports a line directly, Firefox a character offset, and both are normalized here; a deeply nested document (about 100+ levels) can exhaust the parser stack.

Related Tools