How do you fix a JSON syntax error?

One stray comma can make a whole JSON file unreadable. Here's how to spot the mistake and fix it without guessing at your data.

Why can JSON reject text that looks right?

JSON is text for sharing structured information, and its punctuation tells a program how each piece fits.

Think of a JSON object as a filled-in form: each field has a name and a value, and a list holds several values together.

A labelled object contains "name": "Mina" and "routes": ["/health"]. Leaders identify the name, colon, text value, separating comma, list brackets and enclosing object braces.
The punctuation separates the fields and marks where each value begins and ends. How we reviewed

A parser is the part of a program that reads those marks. It can't read past a broken bit of punctuation just because the text makes sense to you. An error location tells you where it got stuck; the mistake can sit just before that spot.

How do you find and fix a trailing comma?

A trailing comma comes after the last item, where JSON expects the list or object to end.

In this routes list, the comma after /ready promises another item. A browser can point at the closing bracket because that's where the promised item fails to appear.

Invalid: {"routes":["/health","/ready",]}. Corrected: {"routes":["/health","/ready"]}. The extra comma is highlighted, with a leader pointing to the closing bracket reported by the browser.
Remove the comma immediately before the closing bracket; the comma between the two routes stays.

How do you fix quotes, separators, and missing closing marks?

Names and text need double quotes, fields need commas between them, and opening marks need matching closing marks.

These repairs change punctuation while leaving the names and values in place.

Three broken-and-fixed pairs: {name: 'Mina'} becomes {"name": "Mina"}; a missing comma between id and state is restored; {"ready":true gains its closing brace. Changed quote marks, comma and brace are highlighted.
Double quotes, a separating comma, or one closing brace can be the whole repair.

An end-of-input message means the parser reached the end while it was still expecting something. A missing closing quote, square bracket, or curly brace is a useful place to look. If an object or list is nested inside another, each opening mark needs its own partner.

Which values belong in JSON?

JSON accepts text, numbers, objects, lists, and the lowercase words true, false, and null.

The value after a colon has to use one of these forms; a familiar JavaScript word isn't necessarily a JSON value.

Accepted values: "Mina", 3, {"id":"A7"}, ["/health", "/ready"], true, false and null. Rejected: undefined, NaN, Infinity, True and a line comment.
Spelling and case count: true is a JSON value; True isn't.

Don't swap an invalid value for null just to clear the error: null means an absent value, and you know what the data should mean. A syntax check checks the writing, not that choice.

If your file includes comments, check the format its destination expects. Comments can belong in JSONC, JSON5, or JavaScript; they don't belong in strict JSON. Functions aren't JSON values either.

How do you fix JSON numbers?

A JSON number can't have an extra leading zero, an unfinished decimal, or an unfinished exponent.

A quantity needs a complete number spelling. An ID with a meaningful leading zero belongs in quotes as text.

Invalid/valid pairs: 01 / 1, 1. / 1.0, and 1e / 1e2. The exponent example assumes two is intended; "01" is separately labelled as a text ID that keeps its zero.
These are spelling examples; the exponent's digits must match the value you intend.

Doing it in FluffyBench

FluffyBench's JSON formatter and validator locates syntax problems and checks your edits as you type.

Here's the routes repair in FluffyBench, from the broken input to the corrected JSON you can copy or download.

  1. FluffyBench JSON formatter with Format JSON selected, the Input tab and the broken routes object.
    FluffyBench JSON formatter with Format JSON selected, the Input tab and the broken routes object.
    Step 1. Keep your original, then paste the JSON into Input. Tap Input to leave the text field and show syntax errors.
    1. Format JSON adds readable spacing.
    2. Tap Input after pasting to show errors.
    3. Paste your JSON here.
  2. The inline error reports Trailing commas are not valid JSON, with a line and character location.
    The inline error reports Trailing commas are not valid JSON, with a line and character location.
    Step 2. Select the first error below Input to jump to the mistake.
    1. Select the problem and its location.
  3. Corrected routes JSON in Input after removing the comma before the closing square bracket.
    Corrected routes JSON in Input after removing the comma before the closing square bracket.
    Step 3. Remove the final comma in Input. FluffyBench checks the edit automatically.
    1. Remove the comma after /ready.
  4. The Result tab shows the valid routes object, with Copy and Download available.
    The Result tab shows the valid routes object, with Copy and Download available.
    Step 4. Open Result to check the formatted JSON. Copy takes the text; Download saves a .json file.
    1. Open Result to read the corrected JSON.
    2. Copy puts the result on your clipboard.
    3. Download saves the JSON file.

If another problem remains, it appears in Input's error list after you leave the text field. For a closer look at what changed, FluffyBench's text diff compares your original and corrected text side by side.

Use FluffyBench's JSON formatter and validator to locate a syntax error

Search FluffyBench