JSON to TypeScript
Paste a JSON response or config file and get the matching TypeScript type definitions (interface / type) on the spot. Nested objects, arrays, null and optional properties are inferred for you. Everything runs in your browser, so the JSON you paste never leaves it.
The name of the outermost type. Nested objects are named automatically from their keys.
How to use the JSON to TypeScript tool
New here? Click one of the "Examples (click to try)" chips above the input. A sample JSON is filled in and its types appear right away. Once you are comfortable, just paste JSON into the textarea. It is a live conversion, so there are no buttons to press. Grab the result with "Copy" or "Download .ts".
Example: typing an API response
For instance, pasting this JSON:
{"id":1,"name":"Aoi","tags":["dev","design"],"profile":{"age":20,"bio":null}}produces this in "interface" mode (root type name Root):
export interface Root {
id: number;
name: string;
tags: string[];
profile: Profile;
}
export interface Profile {
age: number;
bio: null;
}The nested profile is extracted into its own interface and referenced by name from the parent.
- Root type name: names the outermost type (default
Root). Nested objects are named from their keys in PascalCase, with a numeric suffix if a name would clash. - interface / type toggle: tick it to emit a
typealias instead of aninterface. - readonly: adds the
readonlymodifier to every property, handy for response types you treat as immutable. - Inference rules: arrays get
[]on the element type ((A | B)[]when mixed,unknown[]when empty).nullis combined as| null. An array of objects unifies the keys of every element, and keys missing from some elements become optional (?).
Handy for
- Quickly typing an undocumented internal API response
- Bootstrapping an
interfacefrom mock JSON or sample data - Understanding the shape of deeply nested JSON as a type
- Aligning the data shape passed between your frontend and backend
The generated types are inferred from a single sample. Adjust them by hand to match the real API contract (which fields are optional, the range of allowed values, and so on).