withastro/astro · error · AstroError
DataCollectionEntryParseError
DataCollectionEntryParseError
Error message
**${entryId}** failed to parse: ${errorMessage} What it means
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.
Source
Thrown at packages/astro/src/core/config/settings.ts:58
injectedRoutes: [],
resolvedInjectedRoutes: [],
pageExtensions: ['.astro', '.html', ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
contentEntryTypes: [markdownContentEntryType],
dataEntryTypes: [
{
extensions: ['.json'],
getEntryInfo({ contents, fileUrl }) {
if (contents === undefined || contents === '') return { data: {} };
const pathRelToContentDir = path.relative(
fileURLToPath(contentDir),
fileURLToPath(fileUrl),
);
let data;
try {
data = JSON.parse(contents);
} catch (e) {
throw new AstroError({
...AstroErrorData.DataCollectionEntryParseError,
message: AstroErrorData.DataCollectionEntryParseError.message(
pathRelToContentDir,
e instanceof Error ? e.message : 'contains invalid JSON.',
),
location: { file: fileUrl.pathname },
stack: e instanceof Error ? e.stack : undefined,
});
}
if (data == null || typeof data !== 'object') {
throw new AstroError({
...AstroErrorData.DataCollectionEntryParseError,
message: AstroErrorData.DataCollectionEntryParseError.message(
pathRelToContentDir,
'data is not an object.',
),
location: { file: fileUrl.pathname },View on GitHub (pinned to d081033d5f)
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.
Example fix
// before — src/content/authors/jane.json
{ name: 'Jane', age: 30, }
// after
{ "name": "Jane", "age": 30 } Defensive patterns
Strategy: validation
Validate before calling
function validateJsonEntry(file) {
JSON.parse(fs.readFileSync(file, 'utf8'));
} Try / catch
try { data = JSON.parse(raw); } catch (e) { /* report file + e.message */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- BAD_REQUEST
- LiveContentConfigError
- A content collection is defined with legacy features (e.g. m
- Live content collections must be defined in "src/live.config
- Collection loader for ${name} does not have a load method
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/5e3815daeca49691.
Report an issue: GitHub.