“Data collection entry failed to parse.” means a JSON, YAML or TOML file in a content collection isn’t valid, or isn’t an object. The message names the file and the parser’s complaint, for example “authors/ana.json failed to parse: Expected double-quoted property name in JSON at position 45”. Astro’s hint: “Ensure your data entry is an object with valid JSON (for .json entries), YAML (for .yaml entries) or TOML (for .toml entries).” Fix the syntax at the reported position, and make sure each file holds one object.
Key Takeaways
- The bold path in the message is the broken file; the text after “failed to parse:” is the parser’s error.
- JSON trips on trailing commas, comments and single quotes. YAML trips on indentation and unquoted colons.
- With
glob(), each data file is one entry and must contain an object, not a bare string, number ornull.- The
file()loader logs “Error reading data from …” instead of throwing; check the terminal.
Find the error
# Terminal: validate JSON files in a collection folder
for f in src/content/authors/*.json; do node -e "JSON.parse(require('fs').readFileSync('$f','utf8'))" || echo "Bad: $f"; done
For YAML, the message usually includes a line and column, and the dev overlay points at the location. Your editor’s built-in JSON and YAML validation shows the same problems as you type.
Common JSON mistakes
{
"name": "Ana Ruiz",
"role": "Design",
}
The trailing comma after "Design" is invalid JSON. So are // comments, single-quoted strings, and unquoted keys. Remove them:
{
"name": "Ana Ruiz",
"role": "Design"
}
If you want comments, switch the file to YAML or TOML; both are supported data formats.
Common YAML mistakes
name: Ana Ruiz
title: Design lead: brand and web
links:
- https://example.com
- https://example.org
Two problems: a colon followed by a space inside an unquoted value, and a list item indented one space further than its sibling. Quote values with colons and keep indentation consistent with spaces, never tabs:
name: Ana Ruiz
title: "Design lead: brand and web"
links:
- https://example.com
- https://example.org
“data is not an object”
With a glob() loader, every .json file becomes one entry. A file whose top level is a string, a number or null fails with “team.json failed to parse: data is not an object.” A top-level array passes this check but is still one entry, so it then fails your schema. If a file holds a list of items, you have two options:
- Split it into one file per item, each an object.
- Keep the single file and use
file()instead, which turns an array of objects into many entries:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { file } from 'astro/loaders';
import { z } from 'astro/zod';
const team = defineCollection({
loader: file('src/data/team.json'),
schema: z.object({ name: z.string(), role: z.string() }),
});
export const collections = { team };
Each item then needs an id; the content entry missing an id fix covers that.
When file() hides the error
The file() loader doesn’t throw on a parse error. It logs “Error reading data from src/data/team.json” and leaves the collection empty, so your page may render with no data. If a file() collection is empty, check the terminal output and validate the file as above.
Once the file parses, schema problems show up as a different error; see frontmatter does not match schema. The content layer loaders guide explains glob() and file() in detail, our content docs show data collections in Komal Astro themes, and the official collections guide lists supported formats.
FAQ
Can Astro data collections use comments?
Not in JSON, which has no comment syntax. YAML (#) and TOML (#) support comments and work in data collections.
Why does one bad JSON file break the whole build?
Astro parses every entry when it syncs the collection, and a file it can’t parse stops that sync. Fix the named file and the rest load normally.
Does Astro support TOML data files?
Yes. .toml files work in data collections alongside JSON and YAML, and parse errors in them produce the same message.