JSON Formatter, Validator & Syntax Repair

Format JSON with two or four spaces, minify it, sort object keys and inspect parsing errors. Repair common trailing-comma, comment and quote issues locally.

Waiting for input
Samples:
</> Embed this tool on your website / blog No code required · Copy and paste
HTML Embed Code (iframe):
<iframe src="https://lucentool.com/json-formatter" width="100%" height="650" style="border:1px solid #e5e0d8;border-radius:12px;max-width:850px;width:100%;" frameborder="0"></iframe>
<div style="font-size:12px;color:#78716c;margin-top:6px;font-family:sans-serif;">Powered by <a href="https://lucentool.com/json-formatter" target="_blank" style="color:#c85a32;text-decoration:none;">Lucentool - JSON Formatter & Validator</a></div>

Format and inspect JSON

Paste JSON to check its syntax, then choose two-space or four-space formatting, minification, or key sorting. Sorting applies to nested objects as well; array element order stays the same.

Example: sort an object's keys

Enter {"b":2,"a":1} and choose Sort Keys. The result uses two-space indentation:

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

Repair suggestions still need review

Auto-fix handles common comments, trailing commas, single-quoted strings and unquoted keys. It cannot reconstruct missing values or infer your intended data. Parsing uses JavaScript numbers: keep large integer identifiers as strings if exact digits matter. Duplicate object keys are reduced to their last value by JSON parsing.

Edge cases and hard limits

formatJson() parses with JSON.parse and re-serialises with an indent of two or four spaces, which is why the output is guaranteed valid JSON rather than a cosmetic re-flow. sortObjectKeys() walks the parsed tree and rebuilds objects with sorted keys so two files can be compared without ordering noise. autoFixJson() attacks the common hand-written mistakes — trailing commas, comments, single quotes, unquoted keys — by rewriting the source text before parsing. updateMetrics() reports node count and byte size, and flush() debounces the whole pipeline while you type.

Formats, sizes and other limits

The repair step is heuristic, and heuristics can corrupt valid data: a single quote inside a string, a comment marker inside a value, or a trailing comma that was actually part of the content will be rewritten along with the mistakes. Comments are always lost, because JSON has nowhere to keep them. Deeply nested documents can exhaust the parser's recursion, and everything runs on the main thread, so a multi-megabyte file freezes the interface while it formats.

Privacy: processed in your browser

Your JSON is parsed and reprinted inside this tab. The repair pass works on a local copy, and no document, key or value is uploaded or stored between visits.

Frequently asked questions

Can the auto-fix damage valid JSON?

Yes, in edge cases. If the document already parses, format it without the repair option; keep the fixer for text that failed to parse in the first place.

Does it support JSON5 or JSONC?

Only the common subset — comments, trailing commas and unquoted keys get repaired into strict JSON. Exotic JSON5 features such as multiline strings are not supported.

Why does a large file freeze the page?

Parsing and re-serialising happen on the main thread. There is no worker, so the interface cannot repaint until the pass finishes.