Code Beautifier
Unexpected token } in JSON

Fix "Unexpected token } in JSON"

Why JSON.parse throws "Unexpected token } in JSON", almost always a trailing comma before the closing brace, and how to find the exact line and fix it.

Input that triggers it

{
  "name": "Ada Lovelace",
  "roles": ["admin", "editor"],
  "active": true,
}
Open JSON Formatter on its own page
Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

Indent:
json
json

What the error means

Unexpected token } in JSON is the parser telling you it reached a closing brace at a point where the grammar does not allow one. It was expecting something else — a string, a number, an object, an array, true, false or null — and found } instead. Browsers phrase it slightly differently depending on the engine (Unexpected token '}', Expected double-quoted property name in JSON at position 71), but the cause is the same.

The position or line number in the message points at the brace, not at the mistake. The mistake is almost always one character earlier.

Why it happens

  • A trailing comma. JavaScript object literals tolerate { "a": 1, }. JSON does not. After the comma the parser expects another "key": value pair, so the closing brace is "unexpected". This is the cause in the overwhelming majority of cases, and it is exactly what the example above contains.
  • A property with no value. { "name": } fails the same way: after the colon the parser wants a value and gets a brace.
  • An unquoted or single-quoted key further up the object. The parser may recover badly and report the failure at the next brace rather than at the key itself.
  • Hand-edited config where a line was deleted but its preceding comma was not.

How to fix it

  1. Paste the document into the formatter above and click Format. The error card names the line and column of the brace.
  2. Look at the character immediately before that brace, ignoring whitespace. If it is a comma, delete the comma.
  3. If it is a colon, the property is missing its value: either supply one or remove the whole "key": fragment.
  4. Format again. A valid document reformats cleanly; the stats bar shows the size and the key count.

For the example above, the fix is a single character:

{
  "name": "Ada Lovelace",
  "roles": ["admin", "editor"],
  "active": true
}

If the JSON was produced by a language model or copied out of a chat, run it through JSON Repair instead: it removes trailing commas, converts single quotes and Python literals, and strips code fences in one pass, then you can validate the result.

If it still fails

  • Check whether you are pasting two JSON documents back to back, or a document followed by a stray character. That produces a different message, Unexpected non-whitespace character after JSON, and needs the extra content removed rather than a comma.
  • If the error only appears in your application and not in the formatter, the text your code is parsing is not the text you think it is. Log the raw string before JSON.parse — a common surprise is an HTML error page or an empty response body arriving where JSON was expected.
  • Nothing you paste here leaves your browser, so it is safe to check a production payload directly.

Related errors