MergeJSON

How to Repair JSON: Fix Broken, Invalid & AI-Generated JSON

Learn how to repair JSON online - fix trailing commas, single quotes, unquoted keys, comments, Python True/None, smart quotes, and broken AI JSON.

Published June 14, 2026

Invalid JSON usually fails because of tiny mistakes: a trailing comma, a single quote, an unquoted key, or a missing closing brace. AI-generated JSON adds new problems too, like Markdown code fences, Python-style True and None, and smart quotes. This guide shows how to repair JSON safely and understand what changed.

The quickest way: repair JSON online

Paste broken input into the JSON Repair tool and press Repair JSON. The tool fixes common syntax problems, validates the output, and shows a repair log so you can see exactly what changed.

Use a client-side JSON repair tool for private data. Ours runs in your browser, so API payloads, configs, and customer exports do not need to be uploaded to a server.

Use it when: you have almost-JSON that should be valid, but a parser refuses to read it.

Common JSON problems the repair tool can fix

Most invalid JSON comes from formats that look close to JSON but are not actually JSON:

  • Trailing commas - { "a": 1, }
  • Single quotes - { 'name': 'Ada' }
  • Unquoted keys - { name: "Ada" }
  • Comments - // note or /* note */
  • Python values - True, False, and None
  • Smart quotes - curly quotes copied from docs or chat
  • Markdown code fences - wrappers around AI output
  • Unbalanced braces - missing } or ] at the end

After repair, always validate the final JSON. Repair is for syntax cleanup; it cannot know whether the data itself is semantically correct.

JSON repair vs JSON validation

A JSON Validator tells you whether the document is valid and where it breaks. A JSON repair tool tries to turn invalid text into valid JSON.

Use validation when you want strict correctness. Use repair when the input is close to valid and you need a clean parseable version. The best workflow is:

  1. Repair the JSON.
  2. Read the repair log.
  3. Validate the repaired output.
  4. Review any field whose meaning may have changed.

That log matters. If a tool silently changes your data, you cannot trust the result.

Fix AI-generated JSON

Large language models often produce JSON-like output that is helpful but not strict:

{
  "ok": True,
  "items": [1, 2, 3,],
}

Valid JSON requires:

{
  "ok": true,
  "items": [1, 2, 3]
}

For AI output, also remove Markdown code fences and extra prose before or after the object. The repair tool is built for these cases, but you should still inspect the result before using it in production.

Fix invalid JSON by hand

If you want to repair manually, start with the parser error:

  • Unexpected token } often means a trailing comma before }.
  • Unexpected string often means a missing comma.
  • Unexpected end of JSON input means a missing closing brace or bracket.
  • Expected property name often means an unquoted key or stray comma.

Then apply the strict JSON rules: double quotes only, quoted keys, no comments, no trailing commas, lowercase true, false, and null.

Repair JSON in JavaScript

JavaScript’s built-in JSON.parse will not repair input. It only validates:

try {
  const data = JSON.parse(text);
  console.log("valid", data);
} catch (error) {
  console.error("invalid JSON:", error.message);
}

If you need automated repair inside an app, use a dedicated repair library or keep the correction step explicit so users can review the changes.

Which method should you use?

For one-off cleanup, use the online JSON Repair tool: paste, repair, review the log, and copy valid JSON. Use a strict validator when you only want to detect errors. Use code-based repair only when you can test it carefully against the exact broken formats you expect.

After repair, you can format the JSON, compare it with the original, or read common JSON errors and how to fix them.

Ready to merge your JSON?

Combine files or snippets in your browser — free and private.

Open the merge tool

Keep reading