JSON to TypeScript Generator
TypeScript interface will appear here…
Paste any JSON and get a TypeScript interface (or type) instantly — plus an optional Zod validation schema. Nested objects become nested interfaces automatically.
Guide
About JSON to TypeScript Generation
How are nested objects handled?
Each nested object generates a separate interface (or type) declaration. The child interface is named by appending the key name in PascalCase to the parent — e.g., interface RootUser { ... }. All generated types are output in dependency order.
How are arrays typed?
Primitive arrays become string[], number[], etc. Arrays of objects sample the first element to infer the item interface. Mixed-type arrays produce a union type: (string | number)[]. Empty arrays emit unknown[] with a comment so you can fill in the type manually.
What is Zod and why generate it?
Zod is a runtime validation library. While TypeScript types are erased at runtime, a Zod schema validates data shapes in your running application — at API boundaries, on form input, or from localStorage. The generated schema matches the TypeScript interface and can be used to derive the type via z.infer.
Should I use interface or type?
Use interface when you may need to extend or implement it in a class. Use type for unions, intersections, or mapped types. For plain object shapes from JSON, both are functionally equivalent — the choice is a style preference within your codebase.
JSON to TypeScript generation saves significant time when integrating third-party APIs. Instead of manually writing interfaces for every response shape — error-prone and tedious for deeply nested payloads — paste the JSON and get a full set of typed interfaces in seconds. The generated code is a starting point you refine: add JSDoc comments, mark fields optional, or extend interfaces as your understanding of the API evolves.
The type inference engine handles every JSON value type: string, number, boolean, null, arrays, and nested objects at any depth. Arrays are inspected to produce the most specific type possible. Ambiguous cases (empty arrays, mixed-type arrays, null-only fields) are emitted with a // TODO comment so you can make a deliberate choice rather than silently getting any.
Worked example: Paste {"user": {"id": 1, "name": "Alice", "roles": ["admin"]}}. The generator produces two interfaces: interface RootUser { id: number; name: string; roles: string[]; } and interface Root { user: RootUser; }. Switch to the Zod tab to get const RootUserSchema = z.object({ id: z.number(), name: z.string(), roles: z.array(z.string()) }) — ready to use at your API boundary.
The optional Zod schema output is a differentiating feature: it gives you runtime validation that mirrors your compile-time types, using z.infer<typeof schema> to keep both in sync from a single source. This is the pattern recommended by Zod's documentation for typed API clients. Once you have your TypeScript types, you may want to validate and format the JSON it came from, or compare two versions of the API response with the JSON Diff Checker.
JSON to TypeScript vs JSON Schema Generator — which do you need?
Both tools infer structure from JSON, but they serve fundamentally different purposes. JSON to TypeScript (this page) generates compile-time types for TypeScript codebases — the types are erased when the code runs and don't validate data at runtime unless you also use the Zod output. The JSON Schema Generator produces a language-agnostic $schema document that validates data at runtime in any language — Python, Go, Java, or JavaScript via Ajv. Use TypeScript interfaces when you're building a TypeScript/JavaScript frontend or backend; use JSON Schema when you need a portable contract that multiple services or tools can validate against.
After generating your TypeScript types, use the JSON Validator to confirm the original JSON is well-formed, and use the JSON Diff Checker to track changes to API responses over time — an interface that was valid for v1 of an API may break when v2 adds or removes fields.