JSON to TypeScript Generator
Generate TypeScript interfaces and types from JSON data instantly. Supports nested objects, arrays, and customizable root type names.
How to Use
- Paste your JSON data into the left panel.
- Optionally change the Root Name for the top-level interface.
- Toggle type vs interface output style.
- Click Generate Types to create TypeScript definitions.
- Copy the output with the Copy button.
Why Generate Types from JSON?
When working with REST APIs, configuration files, or any external data source, having TypeScript types ensures type safety throughout your codebase. Instead of manually writing interfaces, this tool infers them from a sample JSON response — saving time and reducing errors.
Features
- Nested object support — each nested object generates its own named interface
- Array type inference — arrays of objects create separate item interfaces
- PascalCase naming — property names are converted to PascalCase for interface names
- Safe property keys — keys with special characters are quoted automatically
- interface or type — choose your preferred declaration style
interface vs type in TypeScript
Both interface and type can describe object shapes. Interfaces support declaration merging and are generally preferred for object types. Type aliases support union types and are more flexible. For most API response types, either works — choose whichever your team's style guide recommends.
Related Tools
Validate your JSON before converting with the JSON Validator. Format messy JSON with the JSON Formatter. Convert JSON to CSV with the JSON to CSV Converter. Convert between JSON and YAML with the JSON-YAML Converter. Decode JWT tokens containing JSON payloads with the JWT Decoder.
Frequently Asked Questions
- How does JSON to TypeScript conversion work?
- The tool analyzes your JSON data, infers the types of each field (string, number, boolean, array, nested object), and generates TypeScript interfaces or type aliases that match the structure. Nested objects become separate interfaces.
- Can I use type aliases instead of interfaces?
- Yes. Toggle the "Use type instead of interface" checkbox to generate type aliases with the = syntax instead of interface declarations.
- How are arrays handled?
- Arrays of primitives become typed arrays (e.g., string[]). Arrays of objects are analyzed and a separate interface is generated for the array item type. Mixed arrays are represented as union types.
- What about null values?
- Null values in your JSON are typed as null. You may want to adjust these to the expected type (e.g., string | null) after generation.
- Is my data safe?
- Yes. All type generation happens entirely in your browser. No JSON data is sent to any server.
Code Examples
Learn how to use this tool programmatically in your favorite language.
AI agent tools available.
The CodeTidy MCP Server gives Claude, Cursor, and other AI agents
access to 47 developer tools. One command: npx @codetidy/mcp