JSON to TypeScript
Generate TypeScript interfaces from JSON online, including nested objects and arrays. Paste an API response and copy ready-to-use types into your code.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the JSON to TypeScript
The JSON to TypeScript converter generates interfaces (or type aliases) from a sample response, including nested objects and arrays, so you can type API data without writing it by hand.
Conversion happens in your browser, so your files and records stay private.
How to use the JSON to TypeScript
- Paste a representative JSON sample.
- Set the root type name and choose interface or type.
- Copy the generated types into your project.
Example
Input
{
"id": 42,
"name": "Ada",
"tags": ["admin"],
"address": { "city": "London", "zip": null },
"orders": [
{ "id": 1, "total": 9.5 },
{ "id": 2, "total": 12, "coupon": "SAVE10" }
]
}Result
export interface User {
id: number;
name: string;
tags: string[];
address: Address;
orders: Order[];
}
export interface Order {
id: number;
total: number;
coupon?: string;
}
export interface Address {
city: string;
zip: null;
}Root type name set to "User". "coupon" is optional because only one order has it, and the nested types are named after their keys.
Common mistakes
- null in the sample. A field that is null in your sample becomes the type null. If it can also hold a value, change it by hand, for example zip: string | null.
- One item is not enough. Optional fields are found by comparing items in an array. Paste an array with several representative records, including ones with missing fields.
- Empty arrays. An empty array gives no information about its items. Add at least one element to the sample so the item type can be inferred.
- Types are not validation. Interfaces disappear at runtime. If the API might return something else, validate responses with a schema library such as Zod.
Works well with the JSON to TypeScript
- JSON Formatter: clean up and check the sample before converting it.
- JSON Viewer: inspect deeply nested responses first.
- JSON to SQL Insert: turn the same records into INSERT statements for test data.
Frequently asked questions
How are optional fields detected?
When an array contains objects with different keys, keys missing from some items are marked optional.
Should I trust generated types?
They describe the sample you pasted. Check them against your API documentation, especially for nullable fields.
interface or type alias?
Both describe object shapes. Interfaces can be extended and merged, which suits API models; type aliases are needed for unions. Pick the option your codebase uses.
How are nested objects named?
Each nested object gets its own interface named after its key in PascalCase, such as address → Address, and array items use the singular, such as orders → Order.
Guides and tutorials
- JSON & Data Formats
How to Generate TypeScript Types from JSON API Responses
Turn a JSON sample into TypeScript interfaces, then fix what a generator can't know: nullable fields, optional keys, unions, dates and runtime validation.
· 6 min read
- Programming Languages
TypeScript Strict Mode Explained: Every Flag and the Bugs It Catches
What "strict": true turns on, the real compiler error for each flag, extra checks worth enabling, and a step-by-step plan for migrating an existing codebase.
· 5 min read
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.