{"record":{"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/2d90846af918af9602e088812d63a035d47cdbe4/packages/zod/src/v4/core/json-schema-processors.ts#L114-L150","documentation":"Thrown by toJSONSchema() when a ZodVoid schema (z.void()) is encountered with unrepresentable 'throw' (default). void denotes 'return value ignored' (typically function return types); it has no JSON Schema analogue.","triggerScenarios":"Exporting a schema that includes a z.void() field — often the return type of a z.function() — to JSON Schema. Reusing a function-arity schema (whose arguments/return include z.void()) for documentation.","commonSituations":"RPC-style schemas where z.function(args, z.void()) models a procedure, then trying to serialise the whole shape for OpenAPI.","solutions":["Pass { unrepresentable: 'any' } to toJSONSchema() so void fields become {}.","Drop the function/void portions before exporting; export only the data-carrying parts of the schema.","Model 'no meaningful return' externally as an empty object schema or omit the field."],"exampleFix":"// before (throws)\nconst Schema = z.object({ ack: z.void() });\nz.toJSONSchema(Schema);\n\n// after\nz.toJSONSchema(Schema, { unrepresentable: 'any' });","handlingStrategy":"try-catch","validationCode":"const opts = schemaContains(schema, (s) => s._zod.def.type === 'void')\n  ? { unrepresentable: 'any' }\n  : {};\nconst json = z.toJSONSchema(schema, opts);","typeGuard":"function hasVoid(schema) {\n  return schema._zod.def.type === 'void';\n}","tryCatchPattern":"try {\n  return z.toJSONSchema(schema);\n} catch (e) {\n  if (e.message === 'Void cannot be represented in JSON Schema') {\n    return z.toJSONSchema(schema, { unrepresentable: 'any' });\n  }\n  throw e;\n}","preventionTips":["Do not embed z.function() (which carries z.void() returns) in schemas you export.","Export only data-carrying argument/return schemas, not procedure signatures.","Default to { unrepresentable: 'any' } when exporting RPC-style registries."],"tags":["json-schema","void","unrepresentable","to-json-schema"],"backgroundTag":null,"analyzedSha":"2d90846af918af9602e088812d63a035d47cdbe4","analyzedAt":"2026-08-11T01:21:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}