diff --git a/README.md b/README.md index 18ec943e1..eeff18b41 100644 --- a/README.md +++ b/README.md @@ -1185,9 +1185,9 @@ const Category: z.ZodType = BaseCategory.merge( If you want to validate any JSON value, you can use the snippet below. ```ts -type Literal = boolean | null | number | string; -type Json = Literal | { [key: string]: Json } | Json[]; const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]); +type Literal = z.infer; +type Json = Literal | { [key: string]: Json } | Json[]; const jsonSchema: z.ZodType = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]) ); diff --git a/README_ZH.md b/README_ZH.md index 88fe0d22b..0ca2082c0 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -1012,9 +1012,9 @@ const Category: z.ZodSchema = BaseCategory.merge( 如果你想验证任何 JSON 值,你可以使用下面的片段。 ```ts -type Literal = boolean | null | number | string; -type Json = Literal | { [key: string]: Json } | Json[]; const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]); +type Literal = z.infer; +type Json = Literal | { [key: string]: Json } | Json[]; const jsonSchema: z.ZodSchema = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]) );