It is the smallest possible bug: one comma. The file looks tidy, the data is all there, and the comma even looks deliberate, the kind of thing a careful person adds so the next item is easy to insert. Then the parser rejects the whole file, and the culprit is that single character sitting after the last item.

Trailing commas are the most common reason JSON fails validation, and the most confusing, because the same comma is perfectly legal in several formats developers use every day. This guide explains why strict JSON refuses it, where the habit comes from, and how to clear every trailing comma from a file with the free JSON Formatter and Validator on Ovatly, which runs in your browser with nothing uploaded.

Contents

  • Quick answer
  • What a trailing comma looks like
  • Why the grammar says no
  • Where trailing commas are legal
  • Why files copied from those places fail here
  • The fix loop, step by step
  • Worked example: one comma removed
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

A trailing comma is a comma after the last item in an object or array, right before the closing brace or bracket. JSON treats commas purely as separators between items, so that final comma promises another item that never comes, and the parser rejects the file. The fix takes seconds: paste the file into the JSON Formatter and Validator, run Validate, read the plain-words error, delete the comma it points to, and validate again. Repeat until it passes, because a parser reports only the first error it finds.

What a trailing comma looks like

Here is the mistake in its natural habitat, at the end of an object:

{
  "name": "Ovatly",
  "tools": 250,
  "free": true,
}

And the same thing in an array, just before the closing bracket:

["tools", "free", "online",]

In both cases the data is complete and readable. Nothing is missing, nothing is misspelled. The only defect is a comma with no item after it, and in strict JSON that is enough to invalidate the entire file, not just the line it sits on.

Why the grammar says no

JSON reads a list of items by their separators. Inside an object or array, the parser's logic runs like this: read an item, then look at what follows. A comma means another item is coming, so the parser goes and reads it. A closing brace or bracket means the list is finished.

A trailing comma breaks that contract. The comma announces another item, the parser turns to read it, and finds a closing bracket instead. From the grammar's point of view the file is unfinished, a list cut off mid-sentence, so it is rejected. The comma is not being treated as harmless decoration; it is a structural claim that turns out to be false. That is also why the error can seem to point at the closing bracket rather than the comma itself: the bracket is where the promise gets broken.

The habit of adding them is not carelessness. In everyday development, trailing commas are welcome in several places:

  • JavaScript object and array literals. Modern JavaScript accepts, and many style guides encourage, a trailing comma, because it keeps version-control diffs clean when items are added.
  • JSONC. The JSON with Comments format used for many editor and tool config files allows both comments and trailing commas.
  • JSON5. An extended format designed to be easier to write by hand, which relaxes several JSON rules including this one.

In each case a different, more forgiving parser is doing the reading. The comma is legal there because those grammars say so, not because commas at the end of lists are universally fine.

Why files copied from those places fail here

Most trailing-comma failures arrive by copy and paste. Someone takes an object out of JavaScript code, or a block out of a JSONC settings file, saves it with a .json extension, and hands it to a system that expects strict JSON. The file was valid where it came from and invalid where it landed, with no visible change in between.

That mismatch is worth remembering when any JSON file fails: ask where it was written before asking what is wrong with it. Files born in code editors and config systems often carry JavaScript habits with them, and the trailing comma is usually travelling with its cousins, single-quoted strings and unquoted keys. Our broader guide to JSON syntax rules covers the full strictness list those files tend to break.

The fix loop, step by step

  1. Open the JSON Formatter and Validator and paste in the file that failed.
  2. Click Validate only. This checks the text without changing it, and reports the first problem it finds.
  3. Read the error. It names the problem in plain words, such as an unexpected character, which for a trailing comma means the closing bracket that arrived where an item was promised.
  4. Delete the comma immediately before that closing brace or bracket.
  5. Validate again. If another trailing comma is hiding further down, the next error will point to it. Repeat until the file passes, then Format it if you want the indented version.

Worked example: one comma removed

Start with this object, which carries the mistake on its last line:

{"name":"Ovatly","tools":250,"free":true,}

Validation fails, because the comma after true promises a fourth pair that never arrives. Remove that one comma and the same file validates cleanly, and formatting it gives the readable version:

{
  "name": "Ovatly",
  "tools": 250,
  "free": true
}

One character deleted, nothing else touched. That is the whole repair, and it is why this error, for all the confusion it causes, is the friendliest one a parser can give you.

Limitations and honest tradeoffs

The validator names the problem but does not edit the file for you; the deletion is yours to make, which is deliberate, since a tool silently rewriting data files would be its own kind of risk. The loop also clears errors one at a time, because that is how parsers work, so a long file pasted from a JSONC config may need several rounds before it passes.

Be aware, too, that removing trailing commas makes a file valid JSON but does not convert its other JSONC or JSON5 habits. Comments, single quotes and unquoted keys each need the same treatment. And if the file is meant to stay a config file for a tool that expects JSONC, converting it to strict JSON may not be what you want at all; check what the receiving system actually parses before you tidy anything.

Common mistakes

  • Fixing the first error and assuming the file is clean. Parsers stop at the first problem. Validate again after every fix until it passes.
  • Blaming the closing bracket. The error often points where the bracket sits. The actual defect is the comma just before it.
  • Adding a trailing comma on purpose. A habit worth keeping in JavaScript becomes a bug the moment the text is saved as JSON.
  • Checking only objects. Arrays fail the same way. Scan for commas before closing brackets as well as braces.
  • Saving code as data. An object copied out of a script is JavaScript until it passes a strict validator. Validate before you ship it anywhere.

FAQs

What exactly is a trailing comma? A comma placed after the final item in an object or array, immediately before the closing brace or bracket. JSON requires commas only between items, so that last comma has nothing to separate and makes the file invalid.

Why does JavaScript allow trailing commas but JSON does not? They are different formats with different rulebooks. JavaScript relaxed its grammar to make hand-edited code and diffs nicer. JSON kept the original strict grammar, and its parsers enforce it exactly.

Does the validator remove trailing commas for me? It validates the text and names the problem in plain words, so you know exactly what to delete. The edit itself is yours: remove the comma the error points to, then validate again.

Can one file have several trailing comma errors? Yes, and you will only see them one at a time. A parser stops at the first error it meets, so fix the comma it reports, validate again, and repeat until the file passes.

Are trailing commas a problem in arrays as well as objects? Yes. The rule is identical in both containers: a comma before a closing bracket fails for the same reason as a comma before a closing brace.

Conclusion

A trailing comma fails because JSON commas make a promise: another item follows. Keep commas strictly between items and the file parses. When one slips in from JavaScript, JSONC or JSON5, the JSON Formatter and Validator and the validate, fix, repeat loop will clear it in seconds. For the rest of the strictness family, see the companion guide to JSON syntax rules, and browse the full set in our Data and JSON Tools guides.

References