Skip to content

Commit b898f99

Browse files
committed
Update nullability section
1 parent d9add61 commit b898f99

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

packages/docs/content/json-schema.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,20 @@ z.undefined();
179179
// => { type: "null" }
180180
```
181181

182-
Similarly, `optional` and `nullable` are made nullable via `oneOf`:
182+
Similarly, `nullable` is represented via a union with `null`::
183183

184184
```ts
185-
z.optional(z.string());
186-
// => { oneOf: [{ type: "string" }, { type: "null" }] }
187-
188185
z.nullable(z.string());
189186
// => { oneOf: [{ type: "string" }, { type: "null" }] }
190187
```
191188

189+
Optional schemas are represented as-is, though they are decorated with an `optional` annotation.
190+
191+
```ts
192+
z.optional(z.string());
193+
// => { type: "string" }
194+
```
195+
192196
{/* ### Pipes
193197
194198
Pipes contain and input and and output schema. Zod uses the *output schema* for JSON Schema conversion. */}

play.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { z } from "zod/v4";
22

3-
const User = z.object({
4-
name: z.string(),
5-
get friend() {
6-
return User;
7-
},
8-
});
3+
const User = z.string().optional();
94

105
console.dir(z.toJSONSchema(User), { depth: null });
116
// => {

0 commit comments

Comments
 (0)