JSON Forge
100% Client-Side: your data is never sent to a server

JSON errors

Trailing comma in JSON

The JSON below reproduces this error. See where it breaks, press Fix JSON, or paste your own text.

Loading editor…
Paste or type JSON on the left to explore it as a tree.
Empty🔒 Processed locally in your browser

What the error means

A comma after the last property of an object or the last item of an array is allowed in JavaScript but not in JSON. After the comma the parser expects another key (objects) or value (arrays) and finds a closing brace or bracket instead.

The message looks like this in Chrome, Edge and Node.js (Firefox and Safari use different wording for the same problems):

Expected double-quoted property name in JSON at position 8 (line 1 column 9)
Unexpected token ']', "[1, 2, 3,]" is not valid JSON

Common causes

A comma after the last property

This is the classic mistake when you delete the last line of an object and keep the comma of the line above it. The error names the missing key.

Broken:  {"a": 1,}
Valid:   {"a": 1}

A comma after the last array item

Arrays fail with an error that mentions the closing bracket.

Broken:  [1, 2, 3,]
Valid:   [1, 2, 3]

A file that is really JSONC or JSON5

tsconfig.json, VS Code settings and many tool configs allow comments and trailing commas because their own parsers accept JSONC. JSON.parse does not, so reading such a file with JSON.parse fails. Use a parser that supports JSONC or JSON5, or strip the extras first.

Generated text with a loop that always adds a comma

Building JSON by string concatenation easily leaves a final comma. Build objects and arrays in code and serialise them with JSON.stringify.

How to find the problem

  1. Paste the text that you passed to JSON.parse into the editor above. The status bar shows the line and column of the first problem, and Go to error jumps there.
  2. Remember that the position in the message is where the parser gave up, which is often one token after the real mistake. Look at the character before it as well.
  3. If the text came from a request, log the raw response text before parsing it. In the browser, open the Network tab, select the request and read the Response tab.

Never build JSON by hand

// Fragile: leaves a trailing comma
let out = "[";
for (const x of items) out += JSON.stringify(x) + ",";
out += "]";

// Correct
const out = JSON.stringify(items);

Frequently asked questions

Why do some editors accept trailing commas?

They treat the file as JSONC or JSON5. That is a superset of JSON that JSON.parse and most APIs do not accept.

Will Fix JSON remove them?

Yes. Fix JSON removes trailing commas along with other common problems such as comments and single quotes.

Related errors

All common JSON errors · JSON Validator