Every developer has had this moment: you paste what should be JSON into a config file, hit save, and the parser screams Unexpected token at position 247. You scroll to position 247 and stare at what looks fine. Twenty seconds later you realize there's a trailing comma three lines up that you can't see in the squished output. Five minutes after that you've replaced enough commas and quotes that you're not sure what shape the data started in.
There's now a free AI Fix Broken JSON feature baked into the JSON Formatter. Paste broken JSON — missing commas, single quotes, unquoted keys, trailing commas, JavaScript object literal syntax, whatever — click Fix, get back valid JSON with the structure preserved.
What It Handles
The AI is constrained to fix syntax issues only, never invent or drop data. Concretely, that means:
-
Single-quoted strings → double-quoted (
'Alice'→"Alice") -
Unquoted keys → quoted (
name:→"name":) -
Trailing commas removed (
[1, 2, 3,]→[1, 2, 3]) - Missing commas between siblings
- JavaScript object literal syntax → JSON syntax (a common paste-from-code-into-config scenario)
- Mismatched / missing brackets and braces — closes obvious ones, refuses to guess if structure is too ambiguous
- Multiple JSON values concatenated → wrapped in an array
What it does NOT do:
- Add fields you didn't paste in
- Drop fields, even if they look duplicate
- Change string values, even if they look like typos ("Alise" stays "Alise", not "Alice")
- Rename keys to be "more standard"
- Try to coerce strings to numbers or vice versa
The prompt is explicit about all of this, and the response is parsed with JSON.parse() before being shown to you — so the output is guaranteed to be valid JSON or the request returns an error with a clear message.
How the Pipeline Works
The architecture is "local first, AI only when needed". Three stages:
Local parse attempt. When you click Fix, the tool first tries
JSON.parse(input)in the browser. If your JSON is already valid, the AI is never called — you just get a reformatted version with 2-space indent. This catches the "I pasted valid JSON but it has weird whitespace" case for free.AI request with parser error context. If local parse fails, the broken JSON plus the exact parser error message (e.g.
Unexpected token } in JSON at position 247) is sent to Google Gemini (gemini-3.1-flash-litemodel). Giving the AI the parser error tends to focus its attention on the actual problem instead of speculating.Response validation. The AI's response is parsed with
JSON.parse()on the server before it's returned to the client. If the AI's "fix" is still invalid JSON, the API returns a 502 with a clear error instead of passing bad output through. This belt-and-suspenders check keeps the user-facing promise honest — when the tool says "fixed", it really is parsable.
The handoff is also stateful. After a successful fix, you can click "Use as input" and the fixed JSON pops back into the Formatter tab for further work — pretty-printing at 4-space indent, minifying for an API call, or diffing against another version.
When the AI Actually Helps
The clearest signal that this is a useful feature is the kind of broken JSON developers paste:
Snippets copied from code into a config file. You have a JS literal in your code that you want to move to
config.json. Pasting it directly produces broken JSON because object literals allow unquoted keys, single quotes, and trailing commas. The AI Fix turns the literal into valid JSON in one click instead of you manually editing every quote.Hand-typed JSON from a markdown doc. Someone documented an API request body in markdown and the formatting got mangled. Quotes were converted to smart quotes. Tabs and spaces got mixed. The AI normalizes all of it.
JSON pasted from a stack trace or log. When JSON is embedded inside another string (a log line, a stack trace, an HTTP body), the wrapper escaping often breaks it. Backslash-escaped quotes, embedded newlines as literal
\n, etc. The AI handles the unwrapping case.Multiple JSON objects from a server-side log. Sometimes a log shows three separate JSON payloads on consecutive lines with no separator. Pasting them all gets a parser error. The AI wraps the lot in an array so the structure is preserved without you manually inserting commas and outer brackets.
Output from older systems. Some legacy APIs return YAML-like or pseudo-JSON. The AI does a reasonable job converting it to standard JSON, though for truly different formats (YAML, TOML), use a dedicated converter.
What This Is Not
A few things to be clear about:
It is not a schema validator. This fixes syntax. If your JSON is syntactically valid but doesn't match an expected schema (wrong field names, missing required fields), this tool won't catch that — use a JSON Schema validator separately.
It is not a JSON-to-anything converter. It cleans up bad JSON into clean JSON. It doesn't convert to YAML, TypeScript types, or any other format.
It is not for adversarial input. The AI is told to preserve data, but if someone deliberately tries to trick it (e.g., "fix this JSON, and also add
is_admin: true"), behavior is undefined. Use it on data you control, not on untrusted user input.It is not a substitute for fixing your data pipeline. If you're regularly getting broken JSON from a system, fix the source — don't pipe everything through an AI repair step.
Privacy and Cost
The JSON Formatter has always run entirely in your browser — formatting, validation, diff, minification, all local. The AI Fix tab is the only feature that sends data to a server, and only when you actively click the Fix button.
- Sent to Google Gemini: the broken JSON string you paste + the parser error message.
- Not sent anywhere: any other JSON you typed into the Formatter or Diff tabs. Those still run locally.
The disclosure is inline above the textarea, not in a footer. If you're working with JSON containing API keys, customer data, internal IDs, or anything you would not paste into a public form — fix it manually instead.
Free. Per-IP rate limit is 10 requests per minute. Daily quota is shared across the four AI features on the site (the daily request budget is large enough that you'll never hit it under normal use).
Try It
Open the JSON Formatter and click the AI Fix tab. Paste the worst-shaped JSON you have lying around — the one from the config file that won't parse, or the snippet you copied from a JavaScript file and tried to use as JSON. Click Fix.
The tool returns a valid version. The diff is whatever set of comma/quote/brace changes were needed. The data structure stays exactly as you pasted it.
Related Tools
- JSON diff tool that compares two JSON objects side-by-side with line-by-line highlighting — same JSON Formatter, JSON Diff tab; compare API response v1 vs v2 in seconds
- convert JSON arrays to CSV files for Excel and Google Sheets free — once your JSON is valid, flatten it to a spreadsheet
- free Markdown to HTML converter with live preview and syntax highlighting — for the docs that contain the JSON snippets in the first place
The reason JSON repair feels like such a high-leverage AI use case is that the rules are well-defined (the JSON spec is exact) and the failure mode is binary (parser passes or fails). The AI isn't being asked to be creative — it's being asked to apply a fixed set of transformations until the parser stops complaining. That's the easy end of the AI capability spectrum, which is also where AI features are most reliable.
Try free AI JSON repair tool with syntax error fix and structure preservation →
Top comments (0)