JSON Fixer

Attempts to repair common non-standard JSON mistakes, // and /* */ comments, trailing commas, unquoted object keys, single-quoted strings, curly smart quotes, and bare NaN/undefined, then re-validates the result. This is best-effort, not a guaranteed fix for every malformed document. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

Hand-written or copy-pasted JSON often isn't quite valid, a trailing comma left over from editing, a comment explaining a field, single quotes from a JavaScript object literal.

This tool applies a fixed set of targeted repairs for exactly these common mistakes and re-validates the result.

What Is JSON Fixer?

A best-effort JSON repair tool that applies six specific text transformations, comment stripping, trailing-comma removal, unquoted-key quoting, single-quote conversion, smart-quote normalization, and NaN/undefined replacement, then attempts to parse the result.

It is not a general-purpose parser recovery tool; it targets specific, well-known sources of near-valid JSON, not arbitrary corruption.

How JSON Fixer Works

Smart quotes are normalized to straight quotes first so that a string-aware comment stripper can correctly tell where quoted strings begin and end, then // and /* */ comments outside of strings are removed.

Trailing commas before closing braces/brackets are stripped, bare identifier-like object keys are quoted with a regex, single-quoted strings are converted to double-quoted (with internal quotes re-escaped), and bare NaN/undefined literals become null, before a final JSON.parse confirms the result.

When To Use JSON Fixer

Use it on JSON-like text copied from a JavaScript source file, a config with comments, or a document exported by a tool that used single quotes.

It's also useful as a first pass before manually debugging a document that JSON.parse rejects, since it may resolve the issue outright.

Features

Advantages

  • Handles several common non-standard JSON patterns in one pass instead of fixing them by hand one at a time.
  • Normalizes smart quotes first so comment detection doesn't get confused by word-processor-mangled strings.
  • Clearly reports when repairs were attempted but the result is still invalid, rather than failing silently.

Limitations

  • Cannot fix genuinely mismatched or missing brackets, truncated documents, or other structural damage, only the six specific patterns it targets.
  • The unquoted-key regex is pattern-based, not a real tokenizer, so it can occasionally misfire on unusual key names or values that happen to look like unquoted keys.

Examples

Repairing comments, trailing commas, and unquoted keys

Input

{
  name: 'Ada', // developer
  age: 30,
}

Output

{
  "name": "Ada",
  "age": 30
}

The comment is stripped, the unquoted keys are quoted, the single-quoted string becomes double-quoted, and the trailing comma is removed.

Damage this tool can't fix

Input

{"name": "Ada"

Output

Best-effort repairs were attempted (comments, trailing commas, unquoted keys, single quotes, smart quotes, NaN/undefined) but the result still isn't valid JSON: Unexpected end of JSON input

A missing closing brace is structural damage outside this tool's fixed repair list, so it reports the underlying parse error instead of guessing at a fix.

Best Practices & Notes

Best Practices

  • Run this before manually debugging near-valid JSON, comments and trailing commas are common enough that it often resolves the issue in one pass.
  • If the repair still fails, read the reported parse error, it usually points at the specific structural problem this tool couldn't guess at.
  • Keep a backup of the original text before repairing, since the six targeted fixes rewrite the document rather than only annotating what's wrong.

Developer Notes

Comment stripping tracks string-boundary state character by character (rather than a single regex) so that // or /* sequences inside legitimate string values aren't mistaken for comments, this is why smart-quote normalization runs first, to make sure that string-boundary tracking sees the actual quote characters used to delimit strings.

JSON Fixer Use Cases

  • Repairing JSON-like config copied from a JavaScript or TypeScript source file
  • Cleaning up JSON pasted from a word processor that introduced smart quotes
  • Recovering from a trailing comma left over after editing a JSON document by hand

Common Mistakes

  • Expecting this to fix any invalid JSON; it only targets six specific, common non-standard patterns.
  • Assuming a failed repair means the tool is broken, rather than reading the reported error for the actual structural problem.
  • Using this on JSON that's already valid; it's meant for near-valid JSON with specific, known issues.

Tips

  • Run the repaired output through JSON Formatter afterward for clean, consistent indentation.
  • Follow up with JSON Validator to double check the repaired output before relying on it.

References

Frequently Asked Questions