Free · Fast · Privacy-first

Fix Trailing Comma in JSON

Trailing commas are the single most common cause of JSON parse failures in real projects.

Finds trailing commas with exact line and column

🔒

Explains why trailing commas are invalid in JSON

Free, browser-based, no installation

Works on nested objects and arrays

Cost
Free forever
Sign-up
Not required
Processing
In your browser
Privacy
Files stay local
FreeNo signupWhite-label

Add this JSON Validator to your website

Drop the JSON Validator into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.

  • Files stay 100% in the visitor's browser
  • Responsive — adapts to any container width
  • Free forever, no API key needed

Embed code

<iframe
  src="https://www.fixtools.io/json/json-validator?embed=1"
  width="100%"
  height="780"
  frameborder="0"
  style="border:0;border-radius:16px;max-width:900px;"
  title="JSON Validator by FixTools"
  loading="lazy"
  allow="clipboard-write"
></iframe>

Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.

Trailing Commas: Why They Are Valid in JavaScript but Illegal in JSON

JavaScript added trailing comma support for array literals in ECMAScript 3 and for object literals in ECMAScript 5 back in 2009. Function call argument lists and parameter lists followed in later editions. Major style guides such as Google, Airbnb, and the Node.js community converged on the practice over the following decade because trailing commas produce cleaner diffs when a list grows or shrinks: adding or removing an item changes a single line rather than two. TypeScript outputs trailing commas in many cases. Prettier inserts them by default. The cumulative effect is that developers see trailing commas every day and absorb them as a default convention, then carry the habit into JSON where the grammar does not permit them.

RFC 8259, the JSON specification, defines the array and object productions with an exact pattern. An array is an opening bracket, optionally followed by a value, then a sequence of comma-then-value pairs, then a closing bracket. The grammar puts the comma between values rather than after values. There is no production that allows a comma immediately followed by a closing bracket. The object rule has the same shape with property pairs. The specification predates ECMAScript 5's trailing comma addition, but the design choice was deliberate: JSON is meant to be minimal, unambiguous, and identical across every implementation in every programming language. Permitting an optional trailing comma would require every parser everywhere to handle it.

The fix for a trailing comma error is always a one-character deletion: remove the comma sitting immediately before the closing brace or bracket. In a deeply nested document there may be several trailing commas at different levels, in which case FixTools reports each one with its own line and column. A useful editor technique is to search for the regular expression that matches a comma followed by optional whitespace and then a closing brace or bracket, replacing each match with just the bracket. Always preview each match before replacing because the same pattern can theoretically appear inside a string literal where the comma is data rather than a syntax error.

Catching trailing commas before they reach production is a high-value CI integration that takes minutes to set up. A GitHub Actions or GitLab CI job that runs jq . over every JSON file changed in a pull request fails the build at the first trailing comma it encounters, blocking the merge. For repositories where Prettier is the source of the trailing commas, the durable fix is a Prettier override that sets trailingComma to none for JSON files specifically; once that override is in place, the formatter stops introducing the very error pattern your downstream parser rejects. A pre-commit hook using the standard check-json hook from the pre-commit framework adds another layer of defence on the developer machine. For template-generated JSON, add a test that round-trips a representative output through JSON.parse so any future regression in the template fails the test suite before the change reaches production. Multiple layers of checking compound to eliminate the recurring debugging cost of trailing comma failures.

How to use this tool

💡

Paste JSON that has a trailing comma error. FixTools will find the exact position of the comma so you can remove it and revalidate.

How It Works

Step-by-step guide to fix trailing comma in json:

  1. 1

    Paste the JSON with the trailing comma

    Copy the failing JSON from wherever it lives, whether a config file, an API response, the output of a template, or a generated document. Paste the full content into the FixTools input area so the validator can scan the entire structure. If the failing region is large, paste the whole document anyway rather than trying to extract just the section, because nested errors can cascade and a partial paste may hide them.

  2. 2

    Click Validate

    Click the Validate button to run the parse. The validator reports the first failure as Unexpected closing brace or Unexpected closing bracket along with the exact line and column. The reported position lands on the closing character that the parser saw after the trailing comma, not on the comma itself, because the parser only realised the comma was trailing once it reached the bracket.

  3. 3

    Go to the reported line

    Open the source file in your editor and jump to the reported line and column. The closing brace or bracket at that position is what the validator flagged. The actual trailing comma is the character immediately before that closing character. Position your cursor between the comma and the bracket so you can delete the comma without accidentally removing the bracket or any other surrounding content.

  4. 4

    Delete the comma

    Delete only the trailing comma. Do not delete the closing bracket or any whitespace that you wanted to keep for readability. The bracket itself is correct and necessary. After the deletion, the structure should read as value-then-bracket with no comma between them, which is what the JSON grammar requires. Save the file once the deletion is complete.

  5. 5

    Revalidate

    Paste the updated content into FixTools and click Validate again. JSON parsers fail fast, so a second trailing comma further into the document may now be visible that was hidden behind the first one. Repeat the locate-and-delete cycle for every reported trailing comma until the validator returns a green result. Then fix the source generator so the same failure does not recur on the next document it produces.

Real-world examples

Common situations where this approach makes a real difference:

JavaScript developer

A developer copies a JavaScript object literal from their code into a JSON config file. The object has trailing commas from Prettier formatting. The config loader rejects the file with a parse error on startup. The developer pastes the config into FixTools and sees three trailing commas flagged at different nesting levels in the same document. They delete each one and revalidate after each deletion. The fix takes under two minutes from initial error message to working config. The lesson sticks: JavaScript object literals are not interchangeable with JSON, even when they look identical.

Template engineer

A backend template generates JSON for a configuration endpoint by looping over a list of properties and appending a comma after each one. The loop does not special-case the last iteration, so every generated response carries a trailing comma. Pasting a single response into FixTools confirms the issue in seconds. The real fix is in the template: either iterate with index awareness so the last item omits the comma, or build a comma-separated list using a join operation that handles the boundary correctly. Future responses now validate cleanly.

Config file maintainer

A developer edits JSON-based infrastructure configs in VS Code with the Prettier extension enabled. Prettier is configured for JavaScript with trailingComma set to all, and the team forgot to override the setting for JSON files. The formatter adds trailing commas every time the developer saves. FixTools finds twelve trailing commas in the file. The permanent fix is to add a JSON-specific override in the Prettier config or to add the config file to a .prettierignore entry that excludes it from formatting entirely.

API response debugger

An API response from a legacy system sometimes contains trailing commas in specific response types under specific load conditions. The client team finds the failure intermittently in production logs. They reproduce the conditions in a test environment, capture the raw response with the trailing comma intact, and paste it into FixTools to confirm the pattern. While the upstream team works on a permanent fix, the client implements a defensive trailing-comma-stripping pass on receipt so the application continues to function for affected requests.

Pro tips

Get better results with these expert suggestions:

1

The error points to the bracket, not the comma

When the validator reports a trailing comma failure, the line and column reference the closing brace or bracket that the parser encountered, not the trailing comma itself. The parser does not consider the comma to be a problem until it reaches the closing character and realises there is no following value. The actual trailing comma is one character to the left of the reported position. Delete the comma there, leave the bracket in place, and the structure becomes valid.

2

Use regex to find all trailing commas at once

In any code editor that supports regular expression search, the pattern comma followed by optional whitespace and then a closing brace or bracket finds every trailing comma in a file in one pass. Replace each match with just the captured bracket. Always step through matches with the preview before bulk-replacing because the same pattern can theoretically appear inside a string literal where the comma is data rather than a syntax error and the replacement would corrupt the value.

3

Configure Prettier to avoid trailing commas in JSON

If Prettier is formatting your JSON files and adding trailing commas, add a JSON-specific override in your Prettier configuration that sets trailingComma to none for files matching the JSON extension. Alternatively, add JSON files to your .prettierignore so the formatter skips them entirely. Either approach stops the formatter from introducing the very error pattern your downstream parser rejects, eliminating a recurring source of build failures.

4

Trailing commas are valid in JSON5 and JSONC

If you have a tool that accepts trailing commas without complaint, that tool is parsing the input as JSON5 or as JSON with Comments rather than as strict RFC 8259 JSON. Standard JSON.parse calls in browsers and Node.js will reject the same input. If your workflow legitimately needs trailing commas in configuration files for diff cleanliness, use a parser library that explicitly supports JSON5, such as the json5 npm package, rather than hoping the standard parser will accept the input.

FAQ

Frequently asked questions

A trailing comma is the comma that appears after the final element in an array or after the final property in an object. The pattern looks like an object whose last value is followed by a comma immediately before the closing brace, or an array whose last item is followed by a comma immediately before the closing bracket. Both shapes are valid in JavaScript source code but invalid in JSON. The fix in both cases is to delete the comma before the closing character. The parser will then accept the structure without complaint.
JavaScript added trailing commas to array literals in ECMAScript 3 in 1999 and to object literals in ECMAScript 5 in 2009 as a convenience that produces cleaner diffs when lists grow or shrink. JSON was originally specified in RFC 4627 in 2006 and revised in RFC 8259 in 2017, with a grammar that puts the comma between values rather than after them. JSON aims to be a minimal, language-independent format. Adding an optional trailing comma would require every parser in every language to support it, which conflicts with the goal of simplicity.
Find the trailing comma and delete it. FixTools reports the line and column of the closing brace or bracket that the parser encountered. The trailing comma is the character immediately before that closing character. Open your source file, navigate to the reported line, position your cursor between the comma and the bracket, and delete the comma. Save and revalidate to confirm. If the source of the JSON is generated code, fix the generator so the same trailing comma does not appear in the next output.
In V8, the message is Unexpected token followed by the closing character that the parser saw. The token name will be the closing brace or closing bracket rather than the comma itself, because the parser only realised the comma was trailing once it reached the bracket. In Firefox, the message is SyntaxError: JSON.parse: expected double-quoted property name or closing brace at the line and column of the bracket. In Safari, the message is the terser Expected closing brace. The pattern is the same across engines: the message reports the bracket, but the fix is to delete the comma before it.
Yes. For generated JSON, write the producing code so it never emits a comma after the last element, either by using a join operation that handles the boundary correctly or by checking the iteration index. For hand-written JSON in an editor, configure your formatter to use trailingComma none for JSON files specifically. For CI checks, add an ESLint configuration with eslint-plugin-jsonc and the appropriate no-trailing-comma rule so any commit that introduces a trailing comma fails before it reaches the main branch.
Yes. JSON5, the superset of JSON commonly used for configuration files, explicitly permits trailing commas in both arrays and objects. JSON with Comments, the variant used by VS Code for its own configuration files, also permits trailing commas alongside the comments it allows. If your tool accepts trailing commas, it is parsing one of these variants rather than strict RFC 8259 JSON. Standard JSON.parse in browsers and Node.js does not accept trailing commas regardless of how lenient your configuration tool may be.
The pattern is a comma followed by zero or more whitespace characters and then a closing brace or closing bracket, captured as a group. In most regex engines you replace each match with just the captured group, which removes the comma and keeps the bracket. The pattern can match commas that appear inside string literals if the literal contains the same sequence, so always review each match in your editor before applying the replacement rather than running a blind global substitution that could corrupt string data.
No. A trailing comma is a syntax error that prevents the entire document from parsing. Either the parse succeeds and you get the full structure, or the parse fails and you get a SyntaxError with no partial structure. The parser does not return half a tree. Removing the trailing comma restores the document to a parseable state and all of the original data becomes available. The misconception that a trailing comma might silently drop the last value comes from JavaScript array literals, where the comma can affect the array length, but that behaviour does not apply to JSON.
If a trailing comma persists after a regex substitution that should have removed it, the cause is usually an invisible character between the comma and the closing bracket that the regex did not account for. A non-breaking space at U+00A0, a zero-width space at U+200B, or a Windows carriage return at 0x0D can all sit between the two characters and break a pattern that only matches ASCII whitespace. Switch the whitespace class in your regex to one that includes Unicode whitespace, such as \s in a Unicode-aware engine or the explicit class that includes the relevant code points. Alternatively, paste the document into a hex viewer or a Unicode-aware editor to confirm exactly which bytes sit between the comma and the bracket, then craft a substitution that targets those exact bytes. A hex view of the failing region almost always reveals the culprit immediately.

Ready to get started?

Open the full JSON Validator — free, no account needed, works on any device.

Open JSON Validator →

Free · No account needed · Works on any device