JSON to TypeScript
Paste JSON to generate TypeScript interfaces or type aliases with full nested type inference.
About This Tool
The JSON to TypeScript converter is a free browser-based tool that automatically generates TypeScript interfaces or type aliases from any JSON data. Instead of manually writing type definitions for API responses, configuration files, or database records, you can paste the raw JSON and get accurate, ready-to-use TypeScript types in milliseconds.
The converter performs recursive type inference across your entire
JSON structure. Primitive values are mapped to their corresponding
TypeScript types — string, number,
boolean, and null. Nested objects are
extracted into their own named interfaces or type aliases, with
names derived from the field key (for example, an
address field produces an Address
interface). Arrays are analyzed to determine a consistent element
type; if the array contains mixed types, a union type is generated
automatically. Empty arrays default to unknown[] so
you can refine them later.
All processing happens entirely in your browser. Your JSON data never leaves your machine — there are no server round-trips, no logging, and no third-party analytics on your input. This makes it safe for sensitive payloads such as internal API responses, authentication tokens, and configuration files that contain secrets.
Additional options let you customize the output to match your
project's coding standards. You can toggle between
interface and type alias syntax, mark
all fields as optional with ? for partial types, or
add readonly modifiers for immutable data structures.
The root type name is configurable so the generated code integrates
directly into your codebase without renaming.
How to Use
- Paste or type your JSON into the JSON Input panel on the left.
- The TypeScript output updates automatically in the right panel as you type.
- Set the Root name field to customize the top-level type name (defaults to "Root").
- Click the interface / type toggle to switch between interface declarations and type aliases.
- Enable optional? to mark all fields as optional, or readonly to add readonly modifiers.
- Click Copy or press Ctrl+Shift+C to copy the generated TypeScript to your clipboard.
Popular JSON to TypeScript Examples
FAQ
How does the tool handle nested objects?
Each nested object is extracted into its own named interface or type alias. The name is derived from the field key using PascalCase conversion. For example, a field called shipping_address produces a ShippingAddress interface. If a name collision occurs (e.g. two fields that both normalize to "Item"), a numeric suffix is appended automatically (Item, Item2, Item3, etc.).
What happens with arrays of mixed types?
The converter inspects every element in the array and collects all distinct types. If all elements share the same type, a simple array type is produced (e.g. string[]). If multiple types are found, a union array is generated (e.g. (string | number)[]). Empty arrays default to unknown[].
Is my data safe?
Yes. All type inference and code generation runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.
When should I use interface vs type alias?
In most cases, interface and type are interchangeable for object shapes. Interfaces support declaration merging and are the conventional choice for object types in many codebases. Type aliases are more flexible and can represent unions, intersections, and mapped types. Choose whichever matches your project's conventions.
Can I convert a top-level JSON array?
Yes. If the root JSON value is an array, the tool infers the element type from the array items and produces a named type alias for the array (e.g. type RootArray = Root[]). Each unique object shape in the array still gets its own interface or type.
Related Tools
JSON Formatter
Format, validate, and beautify JSON with syntax highlighting and tree view.
JSON ↔ YAML Converter
Convert between JSON and YAML formats instantly with syntax validation.
CSV ↔ JSON Converter
Convert between CSV and JSON formats with delimiter selection, header toggle, and file drag-and-drop.
JSON Schema Generator
Generate JSON Schema from sample JSON data with type inference, required fields, and nested object support.
JSON to Zod Schema
Convert JSON to Zod schema definitions with type inference, optional/nullable fields, and strict mode.
Protobuf Definition Parser
Parse .proto definitions and visualize messages, fields, enums, services, and RPCs. Convert to JSON Schema or TypeScript interfaces.
JSDoc / TSDoc Generator
Generate JSDoc and TSDoc comment blocks from JavaScript and TypeScript function signatures with @param, @returns, @throws, and @example tags.
TypeScript Utility Types Reference
Interactive reference for all TypeScript built-in utility types with searchable examples, syntax, and playground.