Hunt
Skip to content

JSON Fixer

Paste JSON that won't parse, a JavaScript object or a Python dict, and get valid JSON back. Every change is listed with its line and column, and the tool stops to ask rather than guess when a repair would be ambiguous.

Runs in your browser

Broken JSON

Paste JSON or press Sample

Fixed JSON

The repaired JSON will appear here

What the JSON Fixer does

Most invalid JSON is almost right: it was copied from JavaScript code, a JSON5 or JSONC config file, a Python script or a document that turned the quotes curly. This tool rewrites that text as strict JSON (RFC 8259) and shows you exactly what it changed, so you can check the result instead of trusting it blindly.

Values are copied from your text, never re-calculated, so large numbers such as 12345678901234567890 keep every digit. The repair runs in your browser; nothing you paste is uploaded.

How to use the JSON Fixer

  1. Paste the broken JSON into the left panel, or press Sample to see a typical example.
  2. The repaired JSON appears on the right, with a list of every change below.
  3. Select a change to jump to its location in your input.
  4. Turn off Pretty-print to keep your original layout, then copy or download the result.

Examples

Turn a JavaScript object into JSON

Input
{id: 7, name: 'Ada', tags: ['math', 'code',],}
Output
{
"id": 7,
"name": "Ada",
"tags": [
"math",
"code"
]
}

Property names are quoted, single quotes become double quotes, and both trailing commas are removed.

Convert a Python dict

Input
{'name': 'Ada', 'admin': True, 'manager': None}
Output
{
"name": "Ada",
"admin": true,
"manager": null
}

Remove comments and replace NaN

Input
{
// last run
"score": NaN,
"ratio": .75
}
Output
{
"score": null,
"ratio": 0.75
}

Wrap JSON Lines in an array

Input
{"id": 1}
{"id": 2}
Output
[
{
"id": 1
},
{
"id": 2
}
]

Log files and exports often hold one JSON object per line. Wrapping them in an array makes a single valid document.

What it repairs

Each of these is a common reason for “Unexpected token” errors from JSON.parse:

  • Quotes: single quotes, backticks and curly “smart” quotes become straight double quotes; unquoted property names are quoted.
  • Commas: trailing commas are removed, missing commas between values or properties are added, and semicolons used as separators become commas.
  • Comments: //, /* */ and line-starting # comments are removed.
  • Values: NaN, Infinity and undefined become null; Python's True, False and None become true, false and null.
  • Numbers: +1, .5, 5., 007 and hexadecimal 0xFF are rewritten in JSON form (1, 0.5, 5, 7, 255).
  • Strings: raw line breaks and tabs are escaped, and JavaScript-only escapes such as \' and \x41 are rewritten.
  • Structure: missing closing brackets at the end are added, and several top-level values (JSON Lines) are wrapped in an array.

When it won't guess

Some mistakes have more than one plausible fix. Rather than pick one silently, the tool stops, points to the spot and explains what to do:

  • A bare word used as a value, such as {"status": active}. It might be the text "active", or a variable name from code.
  • A string whose closing quote is missing: the tool can't know where the text should end.
  • A backtick string with a ${…} expression, which has no value without running the code.

Common errors and how to fix them

A word that should be a string

active isn't a JSON value. If you meant the text, quote it; if it came from code, replace it with the variable's value.

Invalid
{"status": active}
Fixed
{"status": "active"}

The tool reports: "active" is not a JSON value. If it is text, put it in double quotes ("active"). The tool doesn't guess, because it could also be a variable or a typo.

A string that never ends

Everything after the opening quote would become part of the string, so the tool asks you to add the closing quote.

Invalid
{"name": "Ada}
Fixed
{"name": "Ada"}

The tool reports: This string is never closed. Add the missing quote; the tool can't tell where the string should end.

A JavaScript template expression

${…} inside a backtick string is evaluated by JavaScript at run time. JSON can only hold the resulting value.

Invalid
{"greeting": `Hello ${name}`}
Fixed
{"greeting": "Hello Ada"}

The tool reports: This backtick string contains a JavaScript expression (${…}), which JSON can't hold. Replace it with the value.

Options

Pretty-print
On (the default), the result is indented with 2 spaces. Off, your original line breaks and spacing are kept and only the broken parts change.

Limitations

  • The fixer repairs syntax, not meaning: check that values replaced with null and quoted words are what you intended.
  • When several problems overlap in a confusing way, the first ambiguous one stops the repair. Fix it and the rest is repaired.
  • Inputs up to 10 MB are supported. Repair runs in your browser.

Frequently asked questions

Is my JSON sent to a server?

No. The repair runs entirely in your browser. Nothing you paste is uploaded, stored or logged, so it is safe to use with API responses, configs and logs.

Will it change my data?

Only where JSON requires it, and every change is listed. Strings and numbers are copied from your text, so large IDs and decimals keep every digit. The exceptions are values JSON can't represent, such as NaN, which become null.

What is the difference between this and the JSON Formatter?

The JSON Formatter checks JSON strictly and tells you exactly what is wrong; the JSON Fixer goes further and repairs the common mistakes for you. Use the formatter when you want to understand an error, the fixer when you just need valid JSON.

Can it convert JSON5 or JSONC?

Yes, for the common features: comments, trailing commas, single quotes, unquoted keys, hexadecimal numbers and leading or trailing decimal points. The result is plain JSON that any parser accepts.

Why does it refuse to fix some input?

Because the fix would be a guess. A bare word like active could be text or a variable, and a string without a closing quote could end anywhere. The tool points to the spot so you can make the decision.