Skip to content
Discussion options

You must be logged in to vote

There is no build-in jsonc parser, but you can use a custom parser e.g.:

import {
  defineCollection,
  defineConfig,
  defineParser,
} from "@content-collections/core";
import JSONC from "comment-json";
import { z } from "zod";

const parser = defineParser((content: string) => {
  const ast = JSONC.parse(content);
  if (ast === null || Array.isArray(ast) || typeof ast !== "object") {
    throw new Error("Invalid content only objects are allowed");
  }
  return ast;
});

const movies = defineCollection({
  name: "movies",
  directory: "movies",
  include: "*.jsonc",
  parser,
  schema: z.object({
    title: z.string(),
    description: z.string(),
    year: z.coerce.number().min(1888).max(n…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JonathonRP
Comment options

Answer selected by JonathonRP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants