PostHog Event to Zod

Paste a posthog event JSON payload and get a Zod z.object schema you can run inside your handler. Same shape walker as the TypeScript-mode page, but the output is a runtime-validated schema with .optional() on missing fields and z.union for nullables.

JSON input valid
Zod output

      
    

About this conversion

PostHog events mix SDK-injected $-prefixed keys with your own custom property names. A parse at the destination (warehouse loader, server-side capture forwarder, webhook export consumer) catches an SDK upgrade adding a field your downstream column doesn't know how to write.

PostHog destinations and warehouse loaders are server-side; they care about validation strictness and good error messages more than bundle KB — Zod's named-error chain is the practical choice when an SDK upgrade introduces a new $-prefixed key. The output is a copy-paste-runnable z.object using only standard Zod primitives (z.string, z.number, z.array, z.union, .optional). Drop it into your handler, run schema.parse(body), and the rest of your code consumes a strongly typed value with no ambient unknowns.

Same shape, other validators

Other JSON shapes