I’ve got a json file where directorlist
and genrelist
are arrays of strings and castlist
is a dictionary (key and value are both strings). I’m trying to create an Astro collection (all other values that are basic strings/numbers work).
import { z, defineCollection } from 'astro:content';
const filmCollection = defineCollection({
type: 'data',
schema: z.array(z.object({
link: z.string(),
title: z.string(),
year: z.string(),
directorlist: z.array(z.string()),
runtime: z.number(),
genrelist: z.array(z.string()),
castlist: z.record(z.string(), z.string()),
tagline: z.string(),
summary: z.string(),
rating: z.number(),
}))
});
export const collections = {
'film': filmCollection,
};
The log just shows undefined.
export async function getStaticPaths() {
const films = await getCollection('film');
films.map(film => {
console.log(film.genrelist)
})
}
I’m lost on what type I should be using in my schema. Any help would be greatly appreciated!