Fix broken JSON from ChatGPT, Claude, or any AI. Auto-adds missing quotes & commas, strips markdown, removes comments. A free JSON formatter, JSON cleaner, JSON beautifier, and JSON viewer โ help you clean my JSON instantly.
Waiting for input
Click "Heal & Format" or paste JSON to begin
A 5-stage surgical repair engine processes your broken JSON
Converts {name: "John"} โ {"name": "John"}. AI models often skip quoting object keys.
Converts 'value' โ
"value" with a safe char-by-char parser that handles escapes and
nested quotes.
Detects and inserts commas between properties the AI
forgot to separate. Never inserts before closing } or ].
Strips the last comma in objects/arrays: [1, 2, 3,] โ [1, 2, 3]. RFC
8259 ยง4 forbids them.
Removes ```json
and ``` wrappers ChatGPT and Claude add around JSON output.
Strips // line and
/* block */ comments. JSON comments are always invalid per RFC
8259.
Converts Python-style True, False, None to JSON-compliant true,
false, null.
Strips leading zeros (0123 โ 123), converts hex
literals, and replaces Infinity/NaN with null.
Detects truncated AI output with unclosed { or [ brackets and appends
the correct closing sequence.
Pretty-prints minified or ugly JSON with correct 2-space indentation for maximum human readability.
Compress formatted JSON into a single line for APIs, config files, or storage โ without losing any data.
Validates final output against RFC 8259. Shows precise error messages if the structure is still invalid after all repair stages.
Strips ```json,
```, and any surrounding code-block markdown that AI models insert around their
JSON responses.
Uses regex to (a) wrap bare unquoted keys in double quotes and (b) convert single-quoted string values to double-quoted ones. Both are extremely common in AI-generated JSON.
Scans for adjacent properties separated only by whitespace or a newline (without a comma), then injects the missing comma character between them.
Removes trailing commas before closing
brackets/braces. In Strict Mode, also strips single-line (//) and multi-line
(/* */) comments from the output.
The repaired text is passed to the JSON5
parser. On success, it's re-serialized with JSON.stringify() into perfectly
indented, standards-compliant JSON. If parsing still fails, the partially-repaired text is
returned with a warning.
Large language models generate JSON
character-by-character using probability distributions. They're not executing a JSON serializer
โ they're predicting the next token. This means they often forget commas, use single quotes,
leave keys unquoted, or wrap output in markdown code blocks (```json) that they
assume you'll strip away. JSONSurgeon's repair engine handles all of these automatically.
JSON is a strict subset of JavaScript with rigid syntax rules: keys must be double-quoted strings, no comments allowed, no trailing commas. JSON5 is a superset that relaxes these rules โ it allows unquoted keys, single-quoted strings, trailing commas, and inline comments. JSONSurgeon uses JSON5 as its parsing backbone because it can accept partially-malformed input, then converts the result back to valid standard JSON.
A trailing comma appears after the last
element in an array or object: [1, 2, 3,] or {"a": 1,}. The JSON
specification (RFC 8259) explicitly forbids them. They're one of the most common errors in
AI-generated JSON. Our tool removes them in Stage 4, and the repaired output will pass any
standard JSON validator.
When Strict Mode is toggled on, the repair
engine performs an additional cleanup step that removes all JavaScript-style comments from your
input (// single line and /* multi-line */). Standard JSON (RFC 8259)
does not allow comments. By default (Strict Mode off), comments are preserved through the JSON5
parser and still result in valid output โ they just won't appear in the final standard JSON
anyway since JSON.stringify() drops them.
Minified or single-line JSON is nearly impossible to read and debug. A JSON beautifier (also called a JSON formatter or JSON pretty printer) adds newlines and indentation to make the structure instantly visible. JSONSurgeon always outputs 2-space-indented, human-readable JSON by default. Use the Minify button when you need compact JSON for APIs or storage.
No. JSONSurgeon runs 100% in your browser. All parsing, repair, and validation happens client-side in JavaScript. Your JSON data never leaves your machine. This makes it safe for sensitive payloads like API keys, tokens, or private configuration files.
JSONSurgeon repairs malformed JSON that appears in everyday AI and copy-paste workflows. It focuses on failure patterns that standard parsers reject immediately: missing commas, unquoted keys, single-quoted strings, trailing commas, comment fragments, markdown fences, and truncated structures. Instead of requiring manual edits, the tool applies staged cleanup rules and then validates output against strict JSON serialization. The result is machine-consumable JSON that can be sent to APIs, stored in configs, or passed to downstream parsers without runtime failures.
This is useful because malformed JSON is rarely random. Most bad inputs follow recurring templates generated by language models or human-edited snippets. A staged repair system can handle these recurring defects faster and more consistently than manual fixes. Developers still need to review semantic correctness, but structural correctness is automated. That distinction is important: JSON repair ensures syntax validity, while business logic validation still belongs in your application layer.
JSON was intentionally designed as a strict data format with limited syntax. Over time, adjacent ecosystems became more permissive. JavaScript allows comments and trailing commas in many contexts. JSON5 and similar relaxed formats tolerate additional syntax for convenience. Then AI assistants started generating text token by token, often wrapping responses in markdown fences or mixing language conventions. The ecosystem now routinely produces "almost JSON" that looks valid to humans but fails strict parsers in production environments.
The operational impact is larger than a simple parse error. Broken JSON can cascade through ETL jobs, webhook handlers, deployment scripts, and test fixtures. Teams lose time debugging formatting defects that are orthogonal to product logic. As LLM output volume increased, this became a scaling problem: even a small malformed-output rate creates frequent incidents. JSON repair tooling emerged to absorb this class of defects at the boundary so core services can assume well-formed input.
Build a deterministic parser-repair pipeline. First, strip markdown wrappers and trim leading commentary that is not part of the payload. Second, normalize quotes and key syntax using conservative transforms that target obvious object-key positions instead of global replacements. Third, remove trailing commas and comments. Fourth, attempt parse with a tolerant parser for intermediate recovery. Fifth, serialize with a strict JSON serializer so output always conforms to standard syntax. Finally, run schema validation to enforce expected fields and types.
Keep transforms ordered and reversible for debugging. Log each stage output when running in development mode, and record which stage resolved parsing failures in production metrics. This helps you identify dominant failure modes and refine rules safely. Avoid over-aggressive regex that mutates text inside quoted strings, because that can silently change data. A robust implementation uses a tokenizer or state machine for quote-aware scanning before applying structural edits.
In an API service, place repair logic at ingress for endpoints that accept AI-generated payloads. If strict parse succeeds, bypass repair and continue. If strict parse fails, run repair stages, then parse again. If parsing still fails, return a clear error with a safe snippet and stage diagnostics. After successful parse, validate against a schema library and reject unknown critical fields when your contract requires strictness. This structure prevents malformed payloads from leaking deeper into your business logic.
Add safety limits to avoid pathological payloads. Cap input size, detect extreme nesting depth, and use parser timeouts where supported. These controls prevent denial-of-service conditions from adversarial or accidental oversized input. For observability, track parse success rate before and after repair, top error signatures, and mean repair latency. With these metrics, you can decide whether to tighten prompts, improve client-side generation templates, or update repair heuristics for new model behavior patterns.
Automatic repair cannot infer missing semantic intent. If a model omits a required field entirely or returns the wrong business value, syntax repair will not fix meaning. Similarly, ambiguous truncation may allow multiple valid closures that parse but represent different data. The correct approach is layered defense: structural repair first, schema validation second, business rule validation third. This sequence keeps data pipelines resilient while preserving correctness guarantees that format-level tools alone cannot provide.
You might also like