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
- Remove any trailing comma before a closing
}or]. - Delete
//or/* */comments - JSON has none. - Balance braces/brackets and quote every key and string.
How to prevent it
- Run
composer validatein CI before install. - Use an editor/JSON linter that flags trailing commas and comments.
- Edit dependencies with
composer require/removerather than hand-editing JSON.
Related guides
Composer "lock file is not up to date" Warning in CIFix Composer "The lock file is not up to date with the latest changes in composer.json" in CI - regenerate th…
Composer "Your requirements could not be resolved" - Fix Dependency ConflictsFix Composer "Your requirements could not be resolved to an installable set of packages" in CI - incompatible…
Composer "Could not find package" - Fix Unknown Packages in CIFix Composer "Could not find a matching version of package X" / "Could not find package" in CI - typos, missi…