fjordtools / Errors / Unexpected token } in JSON

Unexpected token } in JSON (trailing comma)

JSON does not allow a comma after the last item of an object or array, so a text like {"a":1,} is invalid even though JavaScript accepts it in code. Delete the comma before the closing brace or bracket. Comments are not allowed in JSON either.

Fjordtools team · Seen in Chrome and Node (V8) · Published · 1 min read

How browsers word it

Chrome and Node (V8), objectsExpected double-quoted property name in JSON at position 7 (line 1 column 8)
Chrome and Node (V8), arraysUnexpected token ']', "[1,2,]" is not valid JSON
Chrome and Node, olderUnexpected token } in JSON at position 7
FirefoxJSON.parse: expected double-quoted property name at line 1 column 8 of the JSON data

Common causes

  1. A comma after the last property

    Editing by hand or generating JSON with a loop that writes a comma after every item leaves one before the closing brace.

    Input

    {"a":1,}

    JSON Formatter says

    Trailing comma before "}" is not allowed in JSON
  2. A comma after the last array element

    The same mistake in an array. JavaScript and many config formats allow it, JSON does not.

    Input

    [1,2,]

    JSON Formatter says

    Trailing comma before "]" is not allowed in JSON
  3. Comments in the file

    Files such as tsconfig.json and editor settings allow comments and trailing commas (JSONC), but a strict JSON parser rejects them.

    Input

    {"a":1, // note
    "b":2}

    JSON Formatter says

    Expected a key in double quotes but found "/"

How to fix it

  1. Remove the comma before the closing } or ].
  2. Generate JSON with a serializer such as JSON.stringify instead of joining strings.
  3. If the file is JSONC, strip the comments and commas before parsing, or use a parser that supports them.
  4. Paste the text into the JSON formatter: it names the line and column of the first problem.

Related errors

More error explainers are coming

See all errors.