JSON Formatter, Validator, Diff & AI Fix
Format and validate JSON instantly, diff two JSON objects, or paste broken JSON and let AI return the fixed version. Free, no upload.
Formatted JSON will appear here…A JSON formatter, validator, beautifier, and minifier in one tab
Paste a raw API response, a minified config file, a log line, or a mock-data fixture and this free online tool beautifies it into readable, indented JSON while validating the syntax as you type. It is built for the everyday work of developers, QA testers, and anyone wrangling APIs, config files, mock data, or database exports: prettify with 2 or 4-space indent, minify back to one line for production, diff two JSON objects side by side, or paste malformed JSON and let AI Fix repair it.
Formatting, validating, minifying, and diffing all run locally in your browser — there is no upload and no signup. The one exception is the optional AI Fix tab, which sends text to Google Gemini only when you click Fix. Once your JSON is valid you can convert a JSON array to CSV, decode a Base64 payload back into JSON, or beautify the surrounding HTML, CSS, and JavaScript.
How the validator actually works (and what it won’t accept)
The formatter runs on your browser’s built-in JSON.parse() — the same strict parser your code uses at runtime. Every keystroke reparses the input: valid JSON turns the status bar green with a “Valid JSON” badge and re-emits a beautified copy in the output pane; a syntax error turns it red and prints the parser’s exact message and character position, so you can jump straight to the problem. The Indent toggle re-beautifies at 2 or 4 spaces, Minify strips all whitespace to a single line, and Copy and Clear do what they say.
Because it is the strict parser, it only accepts standard JSON. Comments, trailing commas, single-quoted strings, unquoted keys, and JavaScript values like NaN, Infinity, and undefined are all rejected — that is correct behaviour, not a bug. If you are holding a JavaScript object literal or a JSON5-style config, the AI Fix tab can convert it to strict JSON for you.
One honest caveat: the exact wording and position in an error message come from your browser’s JavaScript engine, so Chrome, Firefox, and Safari phrase the same error slightly differently. The message under the input is a starting point, not a contract.
A worked example: beautify, then minify
Say an API hands you this single minified line — 66 characters, impossible to scan:
{"user":"alice","roles":["admin","editor"],"active":true,"age":30}Paste it into the Input pane and the validator beautifies it at 2-space indent — 96 characters across 9 lines, now easy to read and edit:
{
"user": "alice",
"roles": [
"admin",
"editor"
],
"active": true,
"age": 30
}Switch the Indent toggle to 4 and the same object grows to 114 characters; that extra whitespace is purely for humans. When you are ready to ship it in a request body or a config file, click Minify and it collapses straight back to the 66-character single line — same data, smallest payload. Beautify to read and edit, minify to transmit.
Common JSON errors and how to fix them
When the status bar turns red, it is almost always one of these. Each row shows a representative message from a Chromium-based browser and the fix:
| Mistake | Example | Typical parser message | Fix |
|---|---|---|---|
| Trailing comma | {"a":1,} | Expected double-quoted property name in JSON at position N | Delete the comma after the last item; arrays instead report Unexpected token ']' |
| Single-quoted strings | {'a':'b'} | Expected property name or '}' in JSON at position N | Use double quotes for every key and string value |
| Unquoted keys | {a:1} | Expected property name or '}' in JSON at position N | Wrap every key in double quotes |
| Missing comma | {"a":1 "b":2} | Expected ',' or '}' after property value in JSON at position N | Add a comma between each pair or array item |
| NaN / Infinity / undefined | {"a":NaN} | Unexpected token 'N' … is not valid JSON | Replace with null, a real number, or a quoted string |
| Comments | {"a": /* c */ 1} | Unexpected token '/' … is not valid JSON | Strip // and /* */; standard JSON has no comments |
| Leading BOM or hidden char | ⟨U+FEFF⟩{"a":1} | Unexpected token at position 0 (an invisible character) | Re-save as UTF-8 without a BOM, or delete the first character |
| Duplicate keys | {"a":1,"a":2} | No error — parses as {"a":2} | Rename or remove the duplicate; the last value silently wins |
Exact wording and the reported position depend on your browser’s JavaScript engine, so treat the messages above as representative rather than word-for-word. Note the last row: duplicate keys are not a syntax error, so the validator shows “Valid JSON” while quietly keeping only the final value — check for them yourself.
JSON vs JSONC vs JSON5 vs NDJSON — which one are you holding?
“It looks like JSON” often means one of several relatives, and this tool validates the strict form. Knowing which variant you have explains why it fails here and where to take it instead:
| Format | Comments | Trailing commas | One object per line | Typical use |
|---|---|---|---|---|
| JSON (RFC 8259) | No | No | No | Universal data interchange and APIs — the strict form this tool validates and beautifies |
| JSONC | Yes | No | No | Config with comments, e.g. tsconfig.json and VS Code settings |
| JSON5 | Yes | Yes | No | Hand-authored config; also allows single quotes and unquoted keys |
| NDJSON / JSON Lines | No | No | Yes | Log streams and large exports, processed one object per line |
This tool validates and beautifies strict JSON. JSONC and JSON5 win for hand-edited config because they allow comments and trailing commas — but you need a parser that understands them; VS Code and TypeScript, for instance, read JSONC natively. NDJSON is the right call for streaming and huge exports, where you process one object per line rather than loading a single giant array. To turn any of these into strict JSON, the AI Fix tab can often do the conversion.
Beyond formatting: diff two objects and AI-fix broken JSON
Two features set this apart from a plain beautifier.
JSON Diff — normalize, then compare. Paste JSON A (original) and JSON B (modified) into the two panels and the diff appears automatically. Both sides are first parsed and re-serialized to 2-space indent, so pure formatting differences never register as changes; then a Longest Common Subsequence line diff — the same core idea behind git diff — marks added lines green with a +, removed lines red with a −, and unchanged lines plain, with a running “+N added, −N removed, N unchanged” summary and an “identical” verdict when the two match. Because it compares normalized text line by line, reordering object keys or array elements shows up as changes even when the underlying set is the same, and each side is capped at roughly 800 lines — minify or split anything larger.
AI Fix — repair, then re-validate. Paste malformed JSON (up to 10,000 characters) — missing commas, single quotes, unquoted keys, trailing commas, or a whole JavaScript object literal — and click Fix Broken JSON. The tool parses locally first; if the input is already valid it simply reformats to 2-space indent with no AI call. Otherwise the broken text and the parser error go to Google Gemini with strict instructions to preserve every key and value and never invent, drop, rename, or reorder anything, and the server re-parses the model’s answer before returning it, so the output is guaranteed to be valid JSON. “Use as input” drops the repaired result straight into the Formatter.
When not to reach for AI Fix: it is the one feature that leaves your browser, so keep secrets, API keys, and customer data out of it — and it is rate limited to 10 requests per minute per IP. For a simple trailing comma or a missing quote, fixing it by hand from the validator’s error message is faster and keeps everything local.
Frequently asked questions
Formatting, validating, minifying, and diffing run entirely in your browser using the native JSON parser — nothing is uploaded. The one exception is the AI Fix tab: when you click Fix Broken JSON, the text is sent to Google Gemini, so avoid pasting secrets, API keys, or customer data there. AI Fix is rate limited to 10 requests per minute per IP.
It tries the native parser first — if your JSON is already valid it just reformats to 2-space indent, with no AI call. If parsing fails, the broken text plus the parser error is sent to Google Gemini with strict instructions: preserve every key and value, do not invent, drop, rename, or reorder keys, and do not change string values. The server then re-parses the model's output before returning it, so what you get back is always valid JSON. Use as input drops the repaired JSON straight into the Formatter.
Both sides are parsed and re-serialized to 2-space indent, so whitespace and indent differences never create false diffs. It then runs a Longest Common Subsequence line diff — the same core idea behind git diff — and marks added lines green, removed lines red, and unchanged lines plain, with a summary count and an identical verdict when they match. Because it is a line-level comparison of normalized text, reordering keys or array elements shows up as changes. Each side is capped at about 800 lines, so minify or split larger files.
Yes. The Indent toggle beautifies the output at either 2 or 4 spaces and the result updates instantly. Minify does the opposite — it strips all whitespace to a single line for the smallest possible payload, which is what you want for API request bodies and production config.
The validator uses your browser's strict JSON parser, which rejects trailing commas, single-quoted strings, unquoted keys, comments, and values like NaN, Infinity, or undefined. The status bar shows the exact parser message and position. If the input is JavaScript-object-literal style, the AI Fix tab can convert it into strict JSON.
The parser does not treat duplicate keys as an error — it silently keeps the last value, so an object with a repeated key resolves to only its final value and the earlier one is lost without warning. Check for duplicate keys yourself before relying on the formatted output.