best-effort · client-side · single-shot

Auto-repair broken JSON

Fix trailing commas, single quotes, unquoted keys, comments, Python literals, NaN/Infinity, and other common JSON corruptions in one click.

JSON Repair Workspace
Input size
139 B
9 lines
Output size
132 B
repaired
Result
repaired
fixed
Status
Repaired
best-effort
input · broken json
output · repaired
{
  "name": "Ada",
  "age": 36,
  "roles": [
    "admin",
    "founder"
  ],
  "active": true,
  "nickname": null,
  "score": null
}
Step-by-step Tutorial

How to repair common JSON corruption

This tool runs a sequence of safe rewrites to turn loosely-typed input (LLM outputs, Python literals, JS object literals, JSON5, JSONC) into strict RFC 8259 JSON. It's deterministic, conservative, and never invents data.

  1. 01

    Paste broken JSON

    Common sources: LLM outputs that confused JSON with JS, copy-pasted Python dict literals (True, None, single quotes), JSON5 / JSONC config files (tsconfig.json, .vscode/settings.json, babel.config.json), or hand-edited JSON with trailing commas after a refactor.

    Same conservative rules used by the json-repair library and tools like jq's --input-string: only fix what's syntactically ambiguous, never invent missing values.

    Truncated or scrambled input will surface the original parse error so you can fix it by hand.

    LLM outputPython dictJSON5JSONCjson-repair library
    input · broken json3 issues
    {name: 'Ada', score: NaN,}
    26 B · 1 lineunquoted key · trailing comma
  2. 02

    Auto-rewrites run

    The repair pass applies a fixed sequence of regex-safe rewrites: strip line / block comments, convert 'single' → "double" quotes, drop trailing commas before } / ], quote bare object keys per RFC 8259 § 4, and replace NaN / ±Infinity / Python literals (True, False, None) with valid JSON tokens.

    Each step is independent and idempotent — running the output through repair a second time is a no-op. The result parses cleanly with strict JSON.parse.

    For JSON5-specific niceties (hex numbers, leading-plus, escaped newlines), use a dedicated JSON5 parser upstream first.

    RFC 8259 § 4trailing commassingle → double quotescomment strippingPython literals
    rewrites · 5 appliedRFC 8259
    {"name": "Ada", "score": null}
    30 B · 1 linevalid · strict JSON
  3. 03

    Already valid? No-op

    If the input parses cleanly on the first attempt, the repair pass is skipped entirely and the input is pretty-printed instead. Running the tool on already-valid JSON is safe and lossless — original key order is preserved.

    This makes the tool useful as a universal "repair-or-format" step in scripts and pipelines: pipe anything in, get strict JSON out.

    idempotentlosslesskey-order preservedno-op short-circuitsafe
    result · no changesuntouched
    {
      "ok": true
    }
    16 B · 3 linesalready valid · pretty
  4. 04

    Verify with the validator

    Pipe the repaired output through JSON Validator for a final RFC 8259 conformance check, or send it through JSON Formatter for canonical indentation. Use JSON Minifier if you need it on a single line.

    Repair runs entirely in the browser — open DevTools → Network to confirm zero outbound requests, even on sensitive payloads.

    RFC 8259JSON Validatorround-trip safeprivacy-firstverified
    next · verify3 actions
    ✓ Repaired
    ✓ Validated
    ✓ Pretty-printed
    ready to shipRFC 8259 · success
Pro tips

Production-grade JSON, the right way

Stick to RFC 8259

Strict JSON has no NaN, Infinity, comments, or trailing commas. If you need those, look at JSON5 or JSON Repair.

Preserve key order for diffs

JavaScript preserves insertion order, but two parsers shouldn’t be assumed equal. Use Sort JSON Keys before diffing or hashing.

Big integers lose precision

JS numbers lose precision past 2^53−1. Transport large IDs as strings or use BigInt.

Escape inside HTML

When inlining JSON inside <script>, escape </ to <\/ so HTML parsing doesn’t close your tag early.

Validate at boundaries

Trust the wire as little as possible. Run incoming JSON through a schema (Zod / Pydantic) before it touches business logic.

Minify in production

Minify removes whitespace; gzip removes redundancy. Together they typically shrink JSON payloads 70–85% over the wire.

Use Cases

When to repair JSON

Any time strict JSON.parse fails but the source is recoverable.

LLM outputs

AI tools often output near-JSON with single quotes or trailing commas. This catches most of those. Output round-trips losslessly through JSON.parse + JSON.stringify, so the file you save is byte-identical to what you see. Streaming parsers, jq pipelines, and Postgres jsonb columns all accept the result without complaint.

10× faster to scan

Python dict literals

Convert pasted Python dicts (True, None) to JSON.

cleaner PR diffs

JS object literals

Strip unquoted keys and comments from JS object literals you want to ship as JSON. Handles emoji and non-ASCII via UTF-8 throughout — your data survives copy-paste between editors, terminals, and IDEs. Combining marks and ZWJ sequences come out the other side intact.

RFC 8259 valid

JSONC config files

Convert tsconfig.json-style commented JSON to strict JSON for tools that don't support comments.

round-trip safe

Quick fixes

Drop a payload from a logs viewer and clean it up without rewriting by hand. Streams large documents without a server round-trip — privacy stays in the tab. Heavy parsing runs through useMemo so even 5 MB payloads keep the editor responsive.

schema-friendly

Test fixtures

Repair lazily-written test fixtures so they pass strict parse. Output is byte-stable: same input plus same options always produces identical bytes, ideal for content-addressed caches and snapshot tests. Downloads ship with the application/json MIME so editors apply syntax highlighting.

production-ready
FAQ

Frequently asked questions

Conservative — only removes comments, doubles single quotes (everywhere), strips trailing commas, quotes bare keys, and replaces NaN/Infinity/Python literals. No data invention.
Truncated JSON, scrambled structure, missing brackets in the wrong places. If repair fails, it surfaces the parse error so you can fix manually.
No — if the input parses on the first try, it's pretty-printed instead of repaired.
No. All repair runs locally.
Yes.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!