cal.pub0.org/lib/validations/shared/jsonSchema.ts

10 lines
371 B
TypeScript
Raw Normal View History

import { z } from "zod";
// Helper schema for JSON fields
type Literal = boolean | number | string;
type Json = Literal | { [key: string]: Json } | Json[];
const literalSchema = z.union([z.string(), z.number(), z.boolean()]);
export const jsonSchema: z.ZodSchema<Json> = z.lazy(() =>
2022-05-18 15:46:22 +00:00
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]).or(z.null())
);