Skip to content
Discussion options

You must be logged in to vote

I tried applying the solution that @vladyslav-n shared here #4691 a week ago — and it looks like it works! Thank you Vladyslav! 🙏

Working Zod schema for JSON Schema
import { z } from 'zod/v4';

export const NonNegativeInteger = z.int().min(0);
export type NonNegativeInteger = z.infer<typeof NonNegativeInteger>;

export const NonNegativeIntegerDefault0 = z.intersection(
  NonNegativeInteger,
  z.number().default(0)
);
export type NonNegativeIntegerDefault0 = z.infer<
  typeof NonNegativeIntegerDefault0
>;

export const StringArray = z.array(z.string()).default([]);
export type StringArray = z.infer<typeof StringArray>;

export const SimpleTypes = z.enum([
  'array',
  'boolean',
  'integer',

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@MatejBransky
Comment options

@dosubot
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by MatejBransky
Comment options

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

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