{"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/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/core/config/settings.ts#L40-L76","documentation":"The data collection layer parses `.json` files in your content directory with `JSON.parse`. When parsing throws, Astro wraps it as `DataCollectionEntryParseError` with the file path relative to the content dir and the underlying parse message (e.g. \"Unexpected token\"). Empty files are allowed; only invalid JSON triggers this.","triggerScenarios":"A non-empty `.json` entry in the content directory that is not valid JSON: trailing commas, comments, unquoted keys, single quotes, unescaped newlines in strings.","commonSituations":"Hand-editing data files and adding `// comments`; copy-pasting from docs or chat replies that include markdown fences; trailing comma after the last property.","solutions":["Open the file named in the message and fix the syntax at the position given in the parse error.","Remove comments, trailing commas, and quote all keys/values with double quotes.","Run the file through a JSON validator (`npx jsonlint src/content/file.json`) or your editor's JSON language mode.","If you need comments/relaxed syntax, store the data as `.yaml` instead, which the same layer supports."],"exampleFix":"// before: src/content/authors.json\n{\n  \"name\": \"Alice\", // comment not allowed\n}\n\n// after\n{\n  \"name\": \"Alice\"\n}","handlingStrategy":"validation","validationCode":"// Prevalidate data collection JSON before building\nimport { readFileSync, readdirSync } from 'node:fs';\nfor (const f of readdirSync('src/content')) {\n  if (!f.endsWith('.json')) continue;\n  try {\n    JSON.parse(readFileSync(`src/content/${f}`, 'utf-8'));\n  } catch (e) {\n    console.error(`${f}: ${(e as Error).message}`);\n    process.exitCode = 1;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await build();\n} catch (err) {\n  if (err instanceof Error && err.name === 'DataCollectionEntryParseError') {\n    console.error(`Fix ${err.loc?.file ?? 'content file'}: ${err.message}`);\n    return;\n  }\n  throw err;\n}","preventionTips":["Enable JSON language mode / schema validation in the editor for content files.","Ban comments and trailing commas in `.json` data files — switch to `.yaml` if you need them.","Run the prevalidation script as a CI step before `astro build`."],"tags":["content-collections","json","data-layer"],"backgroundTag":"json-parse-error","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}