Hello. I'm trying to use Content Collections API with JSON files that initially contained an array of objects.
Since Astro had trouble reading that structure, I created a Zod schema where the root object has a property that is an array of that same schema.
However, even after this adjustment, Astro still throws the following error:
[InvalidContentEntryDataError] talks → dataday data does not match collection schema.
title**: **title: Required
startDate**: **startDate: Required
endDate**: **endDate: Required
type**: **type: Required
track**: **track: Required
Hint:
It seems Astro is still trying to validate each element inside the array as if it were the root entry instead of using the outer object structure.
content.config.ts
const talkSchema = z.object({
title: z.string(),
description: z.string().optional(),
startDate: z.string(),
endDate: z.string(),
speaker: z.string().optional(),
sponsors: z.array(z.string()).optional(),
type: z.enum(["talk", "break", "sponsor"]),
track: z.array(z.string()),
});
const talks = defineCollection({
loader: glob({ pattern: "**/*.json", base: "src/content/talks" }),
schema: z.object({
talks: z.array(talkSchema),
}),
});
export type Talk = z.infer<typeof talkSchema>;
export const collections = {
talks,
};```
My JSON example:
{
"talks": [
{
"title": "Registro y Recepción",
"startDate": "2025-11-08 08:30:00",
"endDate": "2025-11-08 09:00:00",
"sponsors": [],
"type": "break",
"track": ["track1"]
}
]
}