file() loader
The file() loader populates a collection from a single local data file such as JSON or YAML.
Syntax
loader: file('src/data/authors.json') Returns
Loader — A content loader that turns each record in one file into a collection entry.
Examples
import { defineCollection, z } from 'astro:content';
import { file } from 'astro/loaders';
const authors = defineCollection({
loader: file('src/data/authors.json'),
schema: z.object({
id: z.string(),
name: z.string(),
}),
});
Output
Creates one author entry per object in authors.json, validated by the schema.
Notes
Imported from astro/loaders. Best for a single structured file (JSON, YAML, or a custom parser) containing many records. For arrays, each item should include an id field. Use glob() for many separate files.