Skip to content
Latchkey

Composer "composer.json does not contain valid JSON" in CI

Composer could not parse composer.json because it is not valid JSON. JSON forbids trailing commas and comments, so a stray comma or // note breaks the manifest before anything installs.

What this error means

Any Composer command fails immediately with "composer.json does not contain valid JSON" and a parse error pointing at a line/character. Nothing resolves because Composer cannot read the manifest.

composer output
[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 8:
...    "phpunit/phpunit": "^11.0",  }
---------------------^
Expected one of: 'STRING', '}'

Common causes

Trailing comma or comment

JSON does not allow a comma after the last item in an object/array, nor // or /* */ comments. Either breaks parsing.

A missing brace, bracket, or quote

An unbalanced {}/[] or an unquoted key produces a parse error at the point Composer’s linter gives up.

How to fix it

Validate and locate the bad token

Composer’s validator pinpoints the offending line and character.

Terminal
composer validate --no-check-publish
# or lint the JSON directly
php -r "json_decode(file_get_contents('composer.json')); echo json_last_error_msg();"

Fix the JSON syntax

  1. Remove any trailing comma before a closing } or ].
  2. Delete // or /* */ comments - JSON has none.
  3. Balance braces/brackets and quote every key and string.

How to prevent it

  • Run composer validate in CI before install.
  • Use an editor/JSON linter that flags trailing commas and comments.
  • Edit dependencies with composer require/remove rather than hand-editing JSON.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →