{"id":"f191ee175a5924ec","repo":"colinhacks/zod","slug":"void-cannot-be-represented-in-json-schema","errorCode":null,"errorMessage":"Void cannot be represented in JSON Schema","messagePattern":"Void cannot be represented in JSON Schema","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zod/src/v4/core/json-schema-processors.ts","lineNumber":132,"sourceCode":"export const nullProcessor: Processor<schemas.$ZodNull> = (_schema, ctx, json, _params) => {\n  if (ctx.target === \"openapi-3.0\") {\n    json.type = \"string\";\n    json.nullable = true;\n    json.enum = [null];\n  } else {\n    json.type = \"null\";\n  }\n};\n\nexport const undefinedProcessor: Processor<schemas.$ZodUndefined> = (_schema, ctx, _json, _params) => {\n  if (ctx.unrepresentable === \"throw\") {\n    throw new Error(\"Undefined cannot be represented in JSON Schema\");\n  }\n};\n\nexport const voidProcessor: Processor<schemas.$ZodVoid> = (_schema, ctx, _json, _params) => {\n  if (ctx.unrepresentable === \"throw\") {\n    throw new Error(\"Void cannot be represented in JSON Schema\");\n  }\n};\n\nexport const neverProcessor: Processor<schemas.$ZodNever> = (_schema, _ctx, json, _params) => {\n  json.not = {};\n};\n\nexport const anyProcessor: Processor<schemas.$ZodAny> = (_schema, _ctx, _json, _params) => {\n  // empty schema accepts anything\n};\n\nexport const unknownProcessor: Processor<schemas.$ZodUnknown> = (_schema, _ctx, _json, _params) => {\n  // empty schema accepts anything\n};\n\nexport const dateProcessor: Processor<schemas.$ZodDate> = (_schema, ctx, _json, _params) => {\n  if (ctx.unrepresentable === \"throw\") {\n    throw new Error(\"Date cannot be represented in JSON Schema\");","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/colinhacks/zod/blob/912f0f51b0ced654d0069741e7160834dca742ee/packages/zod/src/v4/core/json-schema-processors.ts#L114-L150","documentation":"`z.void()` (the TypeScript `void` analog) has no JSON representation, so `voidProcessor` (json-schema-processors.ts:130) refuses it when `ctx.unrepresentable === \"throw\"` (default). Typically appears as a function-return or no-content marker in API schemas.","triggerScenarios":"`z.toJSONSchema()` over a schema tree that includes `z.void()`, e.g. modeling an endpoint with no response body, with default options.","commonSituations":"Documenting a no-content (204) API response with a Zod schema; converting function schemas whose return type is void.","solutions":["Use `{ unrepresentable: \"any\" }` in the `z.toJSONSchema()` call.","Drop the void field from the converted schema and represent no-content at the transport layer (HTTP 204) instead.","Replace `z.void()` with `z.null()` or `z.undefined().optional()` if a concrete JSON shape is required."],"exampleFix":"// before\nz.toJSONSchema(z.object({ result: z.void() })); // throws\n// after\nz.toJSONSchema(z.object({ result: z.void() }), { unrepresentable: \"any\" });","handlingStrategy":"fallback","validationCode":"const json = z.toJSONSchema(schema, { unrepresentable: \"any\" });","typeGuard":"function usesVoid(schema: z.ZodType): boolean {\n  return schema._zod.traits.has(\"$ZodVoid\");\n}","tryCatchPattern":"try {\n  return z.toJSONSchema(schema);\n} catch (e) {\n  if (e instanceof Error && /cannot be represented in JSON Schema/.test(e.message)) {\n    return z.toJSONSchema(schema, { unrepresentable: \"any\" });\n  }\n  throw e;\n}","preventionTips":["Model no-content responses at the transport layer (HTTP 204) rather than with `z.void()` in a contract schema.","Use `{ unrepresentable: \"any\" }` for schemas that legitimately include void.","Replace `z.void()` with `z.null()` if JSON must carry an explicit marker."],"tags":["json-schema","void","unrepresentable","openapi"],"analyzedSha":"912f0f51b0ced654d0069741e7160834dca742ee","analyzedAt":"2026-08-03T17:41:55.908Z","schemaVersion":2}