JSON repair — fix trailing commas, quotes, comments and missing brackets

Paste broken or almost-JSON text, such as a JavaScript object, a config with comments or a cut-off API response, and get strict JSON back along with a list of every fix that was made.

Live demo · real result from this tool

Repaired: Removed comments; Quoted unquoted keys (3×); Replaced single quotes with double quotes (3×); Removed trailing commas; Converted Python True/False to true/false; Converted NaN/Infinity to null (JSON has no such numbers); Inserted missing commas; Closed unclosed brackets at the end.

Repaired JSON

{  "name": "Asha Rao",  "roles": [    "admin",    "editor"  ],  "active": true,  "score": null,  "city": "Pune",  "country": "India"}

Fixes applied

  1. Removed comments
  2. Quoted unquoted keys (3×)
  3. Replaced single quotes with double quotes (3×)
  4. Removed trailing commas
  5. Converted Python True/False to true/false
  6. Converted NaN/Infinity to null (JSON has no such numbers)
  7. Inserted missing commas
  8. Closed unclosed brackets at the end

Processed on your device — nothing is uploaded.

How to use JSON repair

  1. Paste the broken text into Broken JSON. The sample shows several common mistakes at once.
  2. Pick an Indent for the output.
  3. Read the notice at the top: either “This was already valid JSON” or “Repaired:” followed by what was changed.
  4. Copy or download the Repaired JSON, and check the Fixes applied list.

If the text cannot be repaired, the tool names the line, column and reason.

What it does and when to use it

Strict JSON rejects many things people write by habit: comments in a config, a trailing comma after the last item, single quotes, keys without quotes, True and None copied from Python, or NaN from a JavaScript log. Data also arrives broken: a response cut off mid-stream, a JSONP callback wrapper, several objects pasted one after another, or a code block copied from documentation or a chatbot. This tool turns all of these into one valid JSON document you can parse.

Use it when a parser throws “Unexpected token” and you just want working data. To see exactly where the first error is without changing anything, use the JSON validator. To convert a real JavaScript object literal into JSON, the JS to JSON converter uses the same tolerant reader. For JSONC files such as tsconfig.json, JSONC to JSON strips comments only.

What it fixes

  • Comments: //, /* */ and #
  • Trailing and extra commas; empty array slots become null
  • Single, curly and backtick quotes; unquoted keys and bare-word values
  • Python True, False, None; JavaScript undefined, NaN, Infinity
  • Hex, octal and binary numbers, +1, .5 and 5.
  • Missing commas and colons, = instead of :, semicolons between properties
  • Unclosed brackets at the end, mismatched closing brackets
  • Markdown code fences, JSONP wrappers, const x = and module.exports = prefixes
  • Several top-level values, which are wrapped in an array

How it works

The text is first tried with the strict parser. If that succeeds, it is only re-indented. Otherwise a tolerant tokenizer reads it piece by piece, records each kind of fix with a count, and builds the value. The value is then printed with JSON.stringify, so the output always follows RFC 8259. It all happens in your browser.

Worked examples

A Markdown code fence marked json, wrapped around {"name": "Asha", "tags": ["a", "b",],}, gives:

Repaired: Removed a Markdown code fence; Removed trailing commas (2×).
{"name":"Asha","tags":["a","b"]}

callback({"ok": true, "count": 0x1F}) gives {"ok":true,"count":31}. Two objects pasted together, {"a":1}{"a":2}, become [{"a":1},{"a":2}].

Limits and tips

  • Repairs are guesses based on common mistakes. A missing quote in the middle of a long string can be “fixed” into a different structure than you meant, so check the result.
  • An unterminated string cannot be repaired; the tool reports where it starts.

Frequently asked questions

Does the repair change my data?
It changes syntax, and a few values where JSON has no equivalent. NaN, Infinity and undefined become null, hex numbers become decimal, and bare words such as pending become strings. Always read the "Fixes applied" list, and compare the result with the original if the data matters.
Why are my large numbers different after repair?
The output is built from JavaScript numbers, which hold integers exactly only up to 2^53 (9,007,199,254,740,991). An ID like 12345678901234567890 comes back as 12345678901234567000, even when the input was already valid. Keep such IDs as strings in the source data.
Can it fix JSON copied from a chatbot answer?
Yes, if the paste is only the code block. A Markdown fence such as ```json is removed. Any sentence before or after the fence makes the repair fail, so copy just the block.
Is this the same as JSON5?
It accepts most JSON5 syntax (comments, single quotes, unquoted keys, trailing commas, hex numbers, leading or trailing decimal points) and goes further with Python literals, curly quotes and missing commas. It is a separate, hand-written parser, not the JSON5 library, and it always outputs strict JSON.
Does it run my code?
No. The text is read as data and never evaluated. Function calls, new expressions and template literals with placeholders are refused with a message instead of being run.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close