JSON β TypeScript
Generate TypeScript, Python, or Go types from JSON automatically
TypeScript interfaces will appear hereβ¦
About this tool
The JSON to TypeScript converter automatically generates TypeScript interface definitions from any JSON object or array. It handles nested objects, arrays, union types from mixed arrays, and optional fields β saving the tedious manual work of writing types by hand from API responses. Beyond TypeScript, it also generates Python dataclasses, Go structs, and Zod schemas from the same JSON β switch languages with one click, quicktype-style, without re-pasting your sample data. The Zod output goes a step further than a plain type: it's runtime-checkable validation code, with string fields that look like an email, URL, UUID, or ISO datetime automatically getting the matching Zod validator (z.string().email(), .url(), .uuid(), .datetime()) instead of a bare z.string().
When to use it
- βCreating TypeScript interfaces from API response payloads
- βGenerating types from database query results or fixture data
- βGetting a typed starting point when adding TypeScript to an existing JavaScript project
- βQuickly typing third-party API responses you don't control
- βGenerating Python dataclasses or Go structs from the same JSON response for a polyglot backend
- βGenerating a Zod schema to validate API responses at runtime, not just type them at compile time
Tips
- βPaste a real API response to generate accurate types β the generator infers types from actual values.
- βFor arrays with mixed element types, the generator creates union types (string | number).
- βReview generated types β null values produce type | null, which may need adjustment based on your API contract.
- βSwitch the language tab to Python, Go, or Zod to generate dataclasses, structs, or a runtime schema from the exact same JSON input.
- βZod's format detection (email, URL, UUID, datetime) is based on the sample values you paste β always double check it against your actual API contract rather than trusting it blindly.
Frequently asked questions
Can generated interfaces replace manually written types?
They give you a solid starting point, but should be reviewed. The generator infers types from a single sample β it can't know that a field is optional (it may just be missing from that response), that an array can be empty, or that a field typed as string | null is actually always a string in production. Treat generated types as a draft.
How are null values handled in generated types?
If a field's value is null in the sample JSON, the generator produces the type null. In practice this is almost always wrong β the field is usually string | null or number | null based on non-null values in other responses. Check each nullable field and update the type to match your actual API contract.
How are deeply nested objects handled?
Nested objects generate nested interfaces. For example, { user: { name: 'Alice', role: { id: 1 } } } produces an interface Root with a user: User property, a User interface with name: string and role: Role, and a Role interface with id: number. The depth is unlimited.
How are arrays of mixed types handled?
Mixed-type arrays produce union types: an array like [1, 'hello', true] generates (number | string | boolean)[]. Homogeneous arrays produce clean types like string[]. If you see unexpected union types, check whether your sample data truly contains mixed element types or whether you need to provide a more representative sample.