{"record":{"id":"c03509aff7eebd8d","repo":"composer/composer","slug":"file-does-not-contain-valid-json-result-messa","errorCode":null,"errorMessage":"\"{file}\" does not contain valid JSON\n{result_message}","messagePattern":"\"(.+?)\" does not contain valid JSON\n(.+?)","errorType":"validation","errorClass":"ParsingException","httpStatus":null,"severity":"error","filePath":"src/Composer/Json/JsonFile.php","lineNumber":398,"sourceCode":"        if (null === $result) {\n            if (defined('JSON_ERROR_UTF8') && JSON_ERROR_UTF8 === json_last_error()) {\n                if ($file === null) {\n                    throw new \\UnexpectedValueException('The input is not UTF-8, could not parse as JSON');\n                } else {\n                    throw new \\UnexpectedValueException('\"' . $file . '\" is not UTF-8, could not parse as JSON');\n                }\n            }\n\n            return true;\n        }\n\n        if ($file === null) {\n            throw new ParsingException(\n                'The input does not contain valid JSON' . \"\\n\" . $result->getMessage(),\n                $result->getDetails()\n            );\n        } else {\n            throw new ParsingException(\n                '\"' . $file . '\" does not contain valid JSON' . \"\\n\" . $result->getMessage(),\n                $result->getDetails()\n            );\n        }\n    }\n\n    public static function detectIndenting(?string $json): string\n    {\n        if (Preg::isMatchStrictGroups('#^([ \\t]+)\"#m', $json ?? '', $match)) {\n            return $match[1];\n        }\n\n        return self::INDENT_DEFAULT;\n    }\n}\n","sourceCodeStart":380,"sourceCodeEnd":414,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Json/JsonFile.php#L380-L414","documentation":"Thrown by JsonFile::validateSyntax() when parsing a JSON file that contains syntax errors. The code at JsonFile.php:378-402 runs the Seld/JsonLint parser; if lint() returns a non-null result (parse error), and a $file path is provided, it throws a ParsingException naming the file and including the linter's message with line/column details. This is the file-based variant of error 18.","triggerScenarios":"Calling $jsonFile->read() or JsonFile::parseJson($json, $path) on a composer.json, composer.lock, or any JSON config file with syntax errors. The linter provides precise error location including a visual caret under the problematic token.","commonSituations":"Manual edits to composer.json introducing a trailing comma, unquoted key, or missing brace. Merge conflicts leaving conflict markers in the JSON. Encoding issues (non-UTF-8 BOM). Copy-paste from formatted text introducing smart quotes.","solutions":["Read the ParsingException message; the linter shows the exact line, column, and a caret pointing to the error.","Run 'composer validate' which reports JSON syntax errors with location.","Use a JSON-aware editor or 'python -m json.tool composer.json' to find the syntax error.","Check for merge-conflict markers, BOM characters, or smart quotes if the error location seems wrong.","Restore from version control and re-apply changes carefully: 'git checkout -- composer.json'."],"exampleFix":"// before: composer.json (trailing comma)\n{\n    \"name\": \"test/package\",\n    \"require\": {\n        \"monolog/monolog\": \"^2.0\",\n    }\n}\n// ParsingException: \"composer.json\" does not contain valid JSON\n\n// after\n{\n    \"name\": \"test/package\",\n    \"require\": {\n        \"monolog/monolog\": \"^2.0\"\n    }\n}","handlingStrategy":"validation","validationCode":"// Validate the JSON file before reading\nuse Composer\\Json\\JsonFile;\n$file = new JsonFile('composer.json');\ntry {\n    $file->validateSyntax(file_get_contents('composer.json'), 'composer.json');\n} catch (\\Seld\\JsonLint\\ParsingException $e) {\n    fwrite(STDERR, $e->getMessage());\n    exit(1);\n}\n$data = $file->read();","typeGuard":"function jsonFileIsValidSyntax(string $path): bool {\n    if (!file_exists($path)) {\n        return false;\n    }\n    try {\n        \\Composer\\Json\\JsonFile::parseJson(file_get_contents($path), $path);\n        return true;\n    } catch (\\Throwable $e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    $data = $file->read();\n} catch (\\Seld\\JsonLint\\ParsingException $e) {\n    // The message includes line, column, and a caret pointer to the error\n    fwrite(STDERR, $e->getMessage());\n    exit(1);\n}","preventionTips":["Run 'composer validate' after editing composer.json.","Use a JSON-aware editor that flags syntax errors.","Check for merge-conflict markers and BOM characters after git operations."],"tags":["json","parsing","syntax","jsonlint","json-file","composer-json"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}