๐ Runs in your browser โ nothing is uploadedโ Free, no signup
JSON to TypeScript Interface Generator
Paste JSON โ like an API response โ to generate TypeScript interfaces instantly. Nested objects, arrays, optional fields and unions are handled for you.
When should you use the JSON to TypeScript?
- Typing an API response in a React, Next.js or Node.js project
- Creating types for a config file or fixture data
- Documenting the shape of a JSON payload for your team
How to use the JSON to TypeScript
- 1
Paste JSON
Paste an object or array into the left editor, or click Load sample.
- 2
Name the root type
Change Root to something meaningful, such as User or ApiResponse.
- 3
Pick a style
Choose interface or type, and whether to export the declarations.
- 4
Copy into your project
Use Copy Output and paste into a .ts file.
Examples
Array items with an optional field
JSON
{
"orders": [
{ "id": 10, "total": 9.5 },
{ "id": 11, "total": 20, "coupon": "SAVE" }
]
}TypeScript
export interface Root {
orders: Order[];
}
export interface Order {
id: number;
total: number;
coupon?: string;
}Common errors and how to fix them
Invalid JSON- The input must be valid JSON. Use the JSON Validator to find the error, or the JSON Formatter's Fix JSON button to repair it.
A field should be optional but isn't- The generator only knows what's in your sample. Include an example item where the field is missing, or add ? by hand.
More from JSON Tools
Free tools that run in your browser โ no signup, nothing uploaded.
JSON Auto-Fixer & Formatter
Repair, validate, and beautify broken JSON (missing quotes, trailing commas).
JSON Validator & Linter
Check JSON syntax and see the exact line and column of every error.
JSON Viewer (Tree)
Explore JSON as a collapsible tree with search and click-to-copy paths.
JSON Editor
Edit JSON with live validation, a tree view, formatting and key sorting.
JSON Beautifier
Pretty-print and indent JSON for easy reading and debugging.
JSON Compare & Diff Tool
Find the difference between two JSON objects visually and quickly.
JSON Sorter (Sort Keys)
Sort JSON object keys alphabetically, including nested objects.
JSONPath Tester
Evaluate JSONPath expressions with filters and recursive queries.
JSON Schema Generator
Generate a JSON Schema from any sample JSON document.
JSON to TypeScript FAQ
Paste a JSON object or array โ for example an API response โ and TypeScript interfaces appear instantly. Nested objects become their own named interfaces.
All objects in the array are merged into one interface. If a key appears in only some items, it's marked optional with ?. If a key has different types across items, it becomes a union like string | null.
Both work for describing object shapes. Interfaces can be extended and merged, and are the common default; type aliases are needed for unions. Tick 'Use type instead of interface' if your codebase prefers type.
The generator can only see your sample. A field that's null everywhere becomes null, and an empty array becomes unknown[]. Paste a sample where those fields have real values, or edit the types afterwards.
Keys that aren't valid TypeScript identifiers are quoted, for example "zip-code": string.
No. Types are generated in your browser, so it's safe to paste real API responses.
