>_ MoriDev dev.moritools.com
TS + Zod 100% Client-Side · Zero Upload

JSON to TypeScript Interface & Zod Schema Generator

Infer clean TypeScript interfaces and runtime Zod validation schemas from raw JSON with union types and optional fields.

Ready (Offline)
Quick Summary

Paste any REST or webhook JSON sample to derive PascalCase TypeScript interfaces alongside matching Zod runtime schemas, complete with optional properties (?) inferred across heterogeneous array elements.

Hand-typing TypeScript interfaces for third-party webhooks or legacy backend APIs is tedious, and compile-time types alone evaporate at runtime the instant an upstream service sends null where a string was documented.

This generator inspects the entire JSON tree, merges object shapes across every element of an array to detect optional properties and nullable unions automatically, deduplicates nested interface names, and emits both clean TypeScript declarations and a ready-to-paste Zod schema with z.infer.

Type Inference Mistakes When Modeling External APIs

01. Sampling Only the First Array Item

Many naïve generators inspect array[0] and ignore array[1..n], missing optional keys or nullable fields that only appear on later records. Merging all elements yields accurate optional (?) and union types.

02. Trusting Compile-Time Interfaces at Network Boundaries

Casting fetch().json() as MyType offers zero runtime protection. Pairing interfaces with a Zod schema at the boundary catches schema drift before undefined crashes UI components.

03. Invalid Identifier Characters in API Keys

Keys like "x-rate-limit" or "@context" are legal in JSON but illegal as bare TypeScript property names. The emitter automatically quotes non-identifier keys while keeping clean keys unquoted.

JSON-to-TypeScript & Zod Mapping

JSON Pattern TypeScript Output Zod Schema
Missing Key in Array Present in some array objects only canary?: number / z.number().optional()
Nullable Value Mixed string and null values string | null / z.string().nullable()
Heterogeneous Array Strings and numbers in one list (string | number)[] / z.array(z.union([...]))
Empty Array [] No sample elements to inspect unknown[] / z.array(z.unknown())
Nested Object Hoisted to dedicated PascalCase interface export interface Metadata { ... }

Worked Engineering Examples

Merging Optional Fields Across Array Objects

Input
[{"region":"iad","canary":10},{"region":"fra"}]
Output
export type Root = RootItem[];

export interface RootItem {
  region: string;
  canary?: number;
}

Because the second object omits canary, the generator marks canary as optional rather than required.

Nullable Union in Zod Output

Input
{"rollbackTarget":null,"id":"dep_1"}
Output
z.object({ rollbackTarget: z.null(), id: z.string() })

Explicit null fields stay visible so you can widen them to .nullable() with one edit when string values are also possible.

Frequently Asked Questions

Can I customize the root interface and Zod schema name?

Yes. Change the Root Type Name input (for example DeploymentEvent) and both the exported TypeScript interface and camelCase Zod constant update immediately.

Why does an empty array infer unknown[] instead of any[]?

TypeScript strict mode discourages any because it disables downstream type checking. Using unknown[] forces explicit narrowing once real array items are known.

How are naming collisions between nested objects resolved?

Each nested object receives a PascalCase name derived from its property key (singularized for arrays), with numeric suffixes appended automatically if two distinct nested shapes share a name.

Does the generated Zod file work with TypeScript strict mode?

Yes. It imports { z } from "zod", exports the schema constant, and exports a derived z.infer<typeof schema> type alias.

Continue Your Workflow

24 offline developer utilities