{"record":{"id":"5e3815daeca49691","repo":"withastro/astro","slug":"datacollectionentryparseerror","errorCode":"DataCollectionEntryParseError","errorMessage":"**${entryId}** failed to parse: ${errorMessage}","messagePattern":"\\*\\*(.+?)\\*\\* failed to parse: (.+?)","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/config/settings.ts","lineNumber":58,"sourceCode":"\t\tinjectedRoutes: [],\n\t\tresolvedInjectedRoutes: [],\n\t\tpageExtensions: ['.astro', '.html', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],\n\t\tcontentEntryTypes: [markdownContentEntryType],\n\t\tdataEntryTypes: [\n\t\t\t{\n\t\t\t\textensions: ['.json'],\n\t\t\t\tgetEntryInfo({ contents, fileUrl }) {\n\t\t\t\t\tif (contents === undefined || contents === '') return { data: {} };\n\n\t\t\t\t\tconst pathRelToContentDir = path.relative(\n\t\t\t\t\t\tfileURLToPath(contentDir),\n\t\t\t\t\t\tfileURLToPath(fileUrl),\n\t\t\t\t\t);\n\t\t\t\t\tlet data;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdata = JSON.parse(contents);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tthrow new AstroError({\n\t\t\t\t\t\t\t...AstroErrorData.DataCollectionEntryParseError,\n\t\t\t\t\t\t\tmessage: AstroErrorData.DataCollectionEntryParseError.message(\n\t\t\t\t\t\t\t\tpathRelToContentDir,\n\t\t\t\t\t\t\t\te instanceof Error ? e.message : 'contains invalid JSON.',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tlocation: { file: fileUrl.pathname },\n\t\t\t\t\t\t\tstack: e instanceof Error ? e.stack : undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (data == null || typeof data !== 'object') {\n\t\t\t\t\t\tthrow new AstroError({\n\t\t\t\t\t\t\t...AstroErrorData.DataCollectionEntryParseError,\n\t\t\t\t\t\t\tmessage: AstroErrorData.DataCollectionEntryParseError.message(\n\t\t\t\t\t\t\t\tpathRelToContentDir,\n\t\t\t\t\t\t\t\t'data is not an object.',\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tlocation: { file: fileUrl.pathname },","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/config/settings.ts#L40-L76","documentation":"Astro's data collections support `.json` entries; the loader's `getEntryInfo` parses each file with `JSON.parse`. When parsing throws (the contents are not valid JSON), the error is caught and re-thrown as `DataCollectionEntryParseError` with the relative path and the parser's message. This gives content authors a content-directory-relative filename instead of a raw Node error.","triggerScenarios":"A `.json` file inside a `src/content/` data collection directory contains a syntax error (trailing comma, unquoted key, single quotes, etc.). The exception in the `try { data = JSON.parse(contents) }` block at `settings.ts:58` triggers the throw.","commonSituations":"Hand-editing JSON and introducing a trailing comma or comment (JSONC not supported here); a script/CSV export producing non-standard JSON; encoding issues (BOM) causing parse failure; merging data and breaking syntax.","solutions":["Open the flagged entry (path in the message) and fix the JSON syntax error.","Validate the file with a JSON linter or `node -e \"JSON.parse(require('fs').readFileSync('FILE','utf8'))\"`.","Use only double-quoted strings and remove trailing commas/comments."],"exampleFix":"// before — src/content/authors/jane.json\n{ name: 'Jane', age: 30, }\n\n// after\n{ \"name\": \"Jane\", \"age\": 30 }","handlingStrategy":"validation","validationCode":"function validateJsonEntry(file) {\n  JSON.parse(fs.readFileSync(file, 'utf8'));\n}","typeGuard":null,"tryCatchPattern":"try { data = JSON.parse(raw); } catch (e) { /* report file + e.message */ }","preventionTips":["Add a pre-commit hook that JSON.lint's content entries.","Use an editor with JSON validation enabled.","Generate JSON programmatically rather than hand-editing where possible."],"tags":["content-collections","json","data","parse-error"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}