JSON to TypeScript Interface
Paste JSON and get ready-to-use TypeScript interfaces for every nested object, with optional fields and unions inferred from your sample. Free, no signup, and generated in your browser so your data is never uploaded.
16 lines · processed in your browser, nothing is uploaded
TypeScript output · root.ts
Generated code appears here.Example: JSON to TypeScript
This JSON sample, with the root type named User, produces the TypeScript below using the default options.
{
"id": 1024,
"name": "Ada Lovelace",
"email": "ada@example.com",
"active": true,
"score": 98.5,
"tags": [
"admin",
"beta"
],
"address": {
"city": "London",
"postcode": "NW1 6XE"
}
}export interface User {
id: number;
name: string;
email: string;
active: boolean;
score: number;
tags: string[];
address: Address;
}
export interface Address {
city: string;
postcode: string;
}
How to convert JSON to TypeScript
- 1Paste a JSON object or array of records into the input.
- 2Select TypeScript as the output language.
- 3Name the root type, for example ApiResponse.
- 4Adjust options such as output style if available.
- 5Copy the interfaces into a .ts file in your project.
Interface or type alias?
For plain object shapes, interface and type are nearly interchangeable. Interfaces can be extended and merged by redeclaration, which suits public API models; type aliases are required for unions, mapped types and tuples.
A common convention is interfaces for objects and type aliases for unions. Pick one style per codebase and let your linter enforce it.
Optional vs null in TypeScript
An optional property (name?: string) means the key may be absent; a nullable one (name: string | null) means the key is present but may hold null. JSON APIs use both, and they are not the same under strictNullChecks.
The generator marks a field optional when it is missing from some records and adds null when it sees null values. Paste several records so both cases are visible.
Union inference and runtime safety
When a field holds different types across records, such as a number in one and a string in another, the output uses a union like number | string. Fields that only ever hold a handful of strings stay typed as string, so narrow them to literal unions yourself if they are really enums.
Interfaces disappear at compile time and do not validate incoming data. If the JSON comes from an untrusted source, also generate a Zod schema and parse responses at runtime.