TFT

JSON to TypeScript Interface Generator

Generate TypeScript interfaces from JSON automatically, including optional fields and nested types. Save hours of manual typing with our free JSON to TypeScript converter.

About JSON to TypeScript Interface Generator

TypeScript developers need interface definitions matching their API data structures. Writing interfaces by hand from JSON samples is tedious and error-prone. This JSON to TypeScript generator creates properly typed interfaces with optional fields and nested type definitions.

How it works

Paste your JSON into the Input area. Set the Interface Name for the root type. Optionally check Use type instead of interface for type alias syntax. Click Generate Interface and get TypeScript definitions with inferred types.

String, number, boolean, and null types are inferred from values. Arrays generate typed array syntax like string[] or Type[]. Nested objects create separate interface definitions. Download saves the result as a .ts file.

When you'd use this

Frontend developers consuming REST APIs need type-safe interfaces for API responses. Teams sharing TypeScript types across projects benefit from consistent interface generation from canonical JSON examples.

The generator marks fields as optional based on inference. For strict type requirements, review and adjust optionality manually. Union types from mixed array values are generated but may need refinement.

Questions

Are fields optional or required?

Fields are marked optional with ? based on inference. Adjust manually based on your API guarantees.

How are arrays typed?

Arrays use the inferred element type like string[] or create a nested interface for object arrays.

What about mixed type arrays?

Mixed arrays generate union types like (string | number)[] to accommodate all observed types.

Can I use type instead of interface?

Yes. Check the Use type option to generate type aliases instead of interface declarations.

Does it handle deeply nested structures?

Yes. Each nesting level generates a separate interface with appropriate naming.