Guide

THE TOOLBOX / TYPESCRIPT & SCHEMA UTILITIES

Infer TypeScript
and Zod schemas.

Paste any JSON API response or fixture to generate nested TypeScript interfaces, type aliases, runtime Zod validation schemas, and JSDoc typedefs locally.

Ready. Paste JSON to infer TypeScript interfaces, Zod schemas, and JSDoc typedefs.

Presets
Generated Types14 lines · 259 B

THE DETAILS

Static TypeScript inference vs. runtime Zod schema validation.

1. Step-by-Step Workflow

Paste a JSON object or array into the input editor, customize the Root Type / Interface Name, choose between export interface and export type, and toggle Optional (?) or Readonly modifiers. Switch output tabs between TypeScript, Zod Schema, and JSDoc @typedef, then copy or download the .ts file.

2. TypeScript 5.x & Zod v3 Standards

Generated TypeScript uses strict types (unknown[] instead of any[] for empty arrays) and automatically quotes non-identifier property keys like "content-type". The Zod tab emits idiomatic z.object({...}) validators with z.number().int() for integers and export type Root = z.infer<typeof rootSchema>.

3. Recursive Child Interface Hoisting

Instead of producing deeply nested inline anonymous object types that are difficult to reuse across components, every nested object is hoisted into its own named PascalCase declaration.

4. Zero-Data-Egress Privacy & Related Tools

Internal API payloads and database records never leave your browser tab. Need to format raw JSON first, inspect an OpenAPI contract, or convert identifier casing? Visit the JSON formatter, OpenAPI validator, and Case & byte converter.

TypeScript vs. Zod vs. JSDoc Comparison Matrix

Output ModeCompile-Time SafetyRuntime ValidationBest Use Case
export interfaceYes (extensible via extends)No (erased at build)Component props & internal models
export typeYes (supports unions/primitives)No (erased at build)Union types & immutable payloads
Zod z.object()Yes (via z.infer)Yes (schema.safeParse())External API & webhook boundaries
JSDoc @typedefYes (in VS Code / checkJs)NoPlain .js / .mjs scripts

Common Type-Inference Pitfalls & Solutions

Single-Sample Null Fields

If a sample JSON response has "avatarUrl": null, a single sample cannot tell whether non-null responses return a string or an object. Widen the generated field to string | null (or z.string().nullable()).

Empty Arrays in Sample Payloads

An empty array [] is inferred as unknown[] rather than any[] so TypeScript still forces narrowing before property access. Include at least one representative item in your sample array for full element inference.

Hyphenated or Numeric Keys

JSON keys like "x-request-id" or "200" are not valid bare TypeScript identifiers and are automatically quoted in both interface and Zod outputs.

Integer vs. Float Distinction in Zod

Whole numbers in your sample JSON emit z.number().int() in Zod. If a field can accept decimal floats in production, remove .int() from that property.

Frequently Asked Questions

Should I use a TypeScript interface, type alias, or Zod schema for API responses?

Use TypeScript interfaces or type aliases when you only need compile-time editor autocompletion and type-checking. Use a Zod schema (z.object) when consuming external REST, GraphQL, or webhook payloads so untrusted data is validated at runtime.

How does the generator handle nested JSON objects and arrays?

Nested JSON objects are recursively extracted into named PascalCase child interfaces (such as UserPayloadProfile), and arrays with mixed element types are inferred as union arrays like (string | number)[].

Are my proprietary API response payloads kept 100% local?

Yes. Type inference and schema code generation run entirely inside your browser JavaScript runtime with zero network requests or telemetry.

Can I mark all generated TypeScript properties as optional or readonly?

Yes. Toggle Optional properties (?) to append ? (and .optional() in Zod) or Readonly properties to prepend readonly to every generated property and array.

How are null values and empty arrays typed in the generated output?

Null properties are typed explicitly as null (or z.null() in Zod) so you can widen them to string | null as needed, and empty arrays default to unknown[] (or z.array(z.unknown())) rather than unsafe any[].