JSON Repair Tool

Paste broken, malformed, or near-JSON text and get valid, parseable JSON back instantly. Fixes trailing commas, missing quotes, truncated output, and AI-generated JSON. Free, private, no signup required.

Open JSON Repair Tool →

Common JSON Errors the Repair Tool Fixes

Malformed JSON appears in many situations: API responses from buggy services, configuration files edited by hand, database exports with encoding issues, and increasingly, structured output from large language models (LLMs) that do not strictly adhere to JSON syntax. The JSON repair tool handles all of the following error categories automatically:

Trailing commas

Standard JSON (RFC 8259) forbids trailing commas - a comma after the last element in an array or the last key-value pair in an object. Many code generators and hand-written configs include them because JavaScript allows them. The repair tool removes trailing commas silently.

// Broken
{"users": ["Alice", "Bob", "Carol",]}

// Repaired
{"users": ["Alice", "Bob", "Carol"]}

Missing or single-quoted strings

Keys and string values must be wrapped in double quotes in JSON. Text from database shells, Python repr() output, or JavaScript object literals often uses single quotes. The repair tool converts single-quoted strings to double-quoted strings and adds missing quotes around unquoted keys.

// Broken (Python-style dict)
{'name': 'Alice', 'active': True, 'score': None}

// Repaired
{"name": "Alice", "active": true, "score": null}

Python and JavaScript literals

Python uses True, False, and None where JSON expects true, false, and null. JavaScript uses undefined which has no JSON equivalent. The repair tool normalizes these to valid JSON values.

Unescaped control characters and special characters

String values in JSON must not contain raw newlines, tabs, or other control characters. These must be escaped as \n, \t, etc. Strings copied from multi-line text fields, terminal output, or log files often contain raw control characters that fail JSON validation. The repair tool escapes them automatically.

Comments in JSON

Standard JSON has no comment syntax. Configuration files that started life as JSONC (JSON with Comments) or were annotated by a developer often contain // line comments or /* block comments */. The repair tool strips all comments and returns clean JSON.

Truncated or incomplete JSON

JSON written to a file or sent over a network may be cut off mid-write due to a crash, timeout, or buffer overflow. Truncated JSON fails to parse because it has unclosed strings, arrays, or objects. The repair tool closes all open structures to produce the most complete and valid representation of the truncated data.

Markdown code block wrappers from LLMs

When asking an LLM like GPT-4 or Claude to produce JSON, the response is frequently wrapped in a markdown code fence: ```json ... ```. This wrapper makes the output invalid JSON. The repair tool detects and strips markdown code fences, returning only the JSON content.

How the JSON Repair Tool Works

The repair process uses a lenient parser that processes the input character by character and builds a corrected output as it goes. Unlike a strict JSON parser that throws an error at the first problem, the repair parser:

  1. Reads tokens one at a time and keeps track of the current nesting context (inside a string, inside an array, inside an object, etc.).
  2. When it encounters a character that would cause a strict parse failure, it applies the most likely correction based on context - for example, replacing a single quote with a double quote when inside a string literal.
  3. Tracks open brackets and braces, and appends the correct closing characters if the input ends before they are closed.
  4. Strips anything that is clearly non-JSON syntax (comments, markdown fences, undefined values).
  5. Outputs the fully corrected JSON string, which is then pretty-printed for readability.

The result is valid JSON that JSON.parse() will accept in any programming language without errors.

When to Use the JSON Repair Tool

Parsing LLM / AI output

Building a product that asks an LLM to return structured JSON is increasingly common. However, LLMs do not always produce perfectly valid JSON - they add trailing commas, wrap the output in markdown, or occasionally output Python-style booleans. Running the repair tool on the raw LLM response before calling JSON.parse() makes your integration more robust and eliminates a whole class of runtime errors.

Recovering crashed application state

Applications that persist state to a JSON file (Electron apps, VS Code extensions, local-first web apps) can produce incomplete JSON if the process crashes mid-write. The repair tool can often recover most of the data from a truncated state file, which may be faster than asking the user to start over.

Cleaning up data exports

Some database export tools and ETL pipelines produce JSON-like output that is not quite valid - often due to encoding issues or column value escaping problems. Running the repair tool on the exported file is faster than modifying the export configuration or writing a custom post-processing script.

Debugging third-party API integrations

When a third-party API returns JSON that your parser refuses to accept, the repair tool helps you identify what exactly is wrong and gives you a corrected version to test against. This is faster than reading the raw response and spotting the error by eye.

Frequently Asked Questions

What errors can JSON Repair fix automatically?+
JSON Repair can fix: trailing commas, missing commas, single quotes instead of double quotes, unquoted property keys, JavaScript-style comments (// and /* */), missing closing brackets or braces, extra brackets, and some encoding issues. It handles the most common hand-edited or API-generated JSON mistakes.
Can the repair tool fix truncated JSON?+
The tool attempts to fix truncated JSON by adding missing closing brackets and braces. This works well for moderately truncated data, but cannot recover data that was genuinely lost — it just makes the structure parseable. Always review the repaired output.
Is the repaired JSON identical to the original intent?+
For simple fixes like trailing commas and quote style, yes — the repaired JSON is semantically identical to the original intent. For more complex repairs (added closing brackets, inferred commas), review the output carefully, especially for arrays with complex nesting.
What is the difference between JSON Repair and JSON Formatter?+
The JSON Formatter works only on already-valid JSON and reformats it. The JSON Repair tool accepts invalid or malformed JSON and attempts to fix it first, then format it. Always validate the repaired output before using it in production.
Can I repair JSON from copied console output?+
Yes. Console output often has JavaScript object literal format (unquoted keys, single quotes) which isn't valid JSON. Paste it into the repair tool and it converts it to proper JSON with double-quoted strings and keys.
What should I do if the repair tool cannot fix my JSON?+
If automatic repair fails, use the error message to identify the exact location. The JSON Validator gives precise error locations (line and column). For common patterns, check the JSON validation errors guide.

Ready to fix your broken JSON?

Free, instant, 100% private. No account needed.

Open JSON Repair Tool →

Also useful: JSON Validator | CSV to JSON Converter | JWT Decoder | JSON Guides