toolgarden.xyz
中文

JSON Repair / Clean

Free online JSONC / JSON5 repair tool for comments, trailing commas, single quotes, unquoted keys, and other common JSON issues

JSON to repair

Repaired output

Standard JSON will appear here

About this tool

"JSON failed to parse" covers two very different situations. In one the text is genuinely broken; an unclosed quote, half a bracket. In the other the text is perfectly sensible but written in a dialect outside strict JSON: comments, trailing commas, single quotes, unquoted keys. The second case is everywhere in config files, and a strict parser rejects it just as flatly as real corruption. This tool is for that second case.

A second common source is copy and paste. Content lifted out of a log line, a database column, or a string value inside another JSON document usually arrives escaped one level deep, with a backslash before every double quote. It looks like JSON, but it is the literal of a JSON string and has to be unescaped before it will parse.

How to use it

  1. Paste the whole thing that will not parse

    No manual cleanup first. Comments, trailing commas, single quotes, unquoted keys and stray escape backslashes can all be present at once and are handled in a single pass.

  2. Check the repair against the original

    The output is strict RFC 8259 JSON. Comparing the two sides shows exactly what changed; repair only touches syntax, never adding, removing or altering a value.

  3. Read the error position if it still fails

    When the text is genuinely damaged; unbalanced brackets, an unterminated string, a truncated body; there is nothing to infer from. You get the failing position instead, and have to go back to the source.

  4. Hand the strict JSON onward

    From here it goes straight into JSON Formatter for the tree view, JSONPath Query to pull a field, or conversion to YAML, CSV or a TypeScript type.

Input and output example

A typical JSONC config fragment: a comment, a single-quoted key, a trailing comma. A strict parser refuses all three.

Rejected by a strict parser
{
  // 服务端口,改这里要同步改 nginx
  'host': "127.0.0.1",
  port: 8080,
  tags: ['api', 'internal',],
}
Repaired to strict JSON
{
  "host": "127.0.0.1",
  "port": 8080,
  "tags": [
    "api",
    "internal"
  ]
}

Supported range and limits

Comments
Recognises and removes `//` line comments and `/* */` block comments
Trailing commas
Drops the extra comma after the final member of an object or array
Quoting
Converts single-quoted strings to double quotes and adds quotes to bare keys
Over-escaping
Detects text escaped one level deep, unescapes it, then parses
Not repairable
Unbalanced brackets or quotes and truncated content; these need the original source; nothing is guessed
Where it runs
Entirely in your browser; what you paste is never sent to a server

When you would use it

  • Moving an editor config somewhere strict

    tsconfig.json, .eslintrc.json and VS Code settings.json are all JSONC. Comments and trailing commas have to go before a strict parser; or an environment variable; will accept them.

  • Recovering a response copied out of a log

    Logs routinely print a whole response body as a string, which puts a backslash before every double quote. Unescaping that layer is what turns it back into parseable JSON.

  • Inheriting a data file of unknown provenance

    A hand-written .json from someone else often mixes single quotes with trailing commas. Repairing then validating is far quicker than editing line by line, and far less likely to corrupt a value on the way.

What to know before you start

  • Repair changes syntax, not meaning. It will not supply a missing field, guess at truncated content, or correct a value that looks implausible; those calls are yours.
  • Comments disappear from the output, because strict JSON has no syntax to hold them. If those comments matter for maintaining the config, keep the original JSONC file and use the repaired output only where strict JSON is required.
  • Duplicate keys resolve last-one-wins, which is standard JSON parsing behaviour. A key that appeared twice in the input appears once in the output; worth watching for when you compare the two sides.
  • Numbers still go through JavaScript number semantics. JSON5 hexadecimal literals come back as decimal, and very long integers lose precision; carry those as strings if the exact digits matter.

Related concepts

RFC 8259
The current JSON standard. It permits no comments, no trailing commas, no single-quoted strings and no bare keys; which is exactly why a perfectly valid config file gets rejected.
Trailing comma
A comma after the last member of an array or object. Legal in JavaScript and JSON5, illegal in strict JSON, and the single most common cause of a parse failure.
Double escaping
What you get when one JSON document is embedded as a string value inside another: a backslash before every double quote. One level of unescaping recovers the original.

Frequently asked questions

Which common JSON errors can it fix?
It removes comments and trailing commas, converts single-quoted and unquoted keys to standard double quotes, and turns JSONC / JSON5 into valid JSON.
Can it clean up JSON returned by an LLM?
Yes. Typical AI output issues like trailing commas, comments and single quotes are repaired automatically into valid, parseable JSON.
Is the repair process private?
Repair runs entirely in your browser and nothing is uploaded, so it is safe for config files containing keys or personal data.
Does repairing change my data?
No. Only syntax is touched; quoting, commas, comments, escaping. Field names and values come through unchanged, with the single exception that duplicate keys collapse to the last occurrence, per standard JSON behaviour.
Why can some text not be repaired?
Because missing information cannot be inferred. Unbalanced brackets, an unterminated string or a body cut off mid-way all mean characters are gone from the original. The tool does not guess, because a wrong guess is more dangerous than an error.
How is this different from the JSON formatter?
The formatter assumes the input parses and re-lays it out; repair deals with input that does not parse at all. In practice you repair first and format second; though the formatter also accepts JSONC and JSON5 directly.