JSON to TypeScript Converter
Paste a JSON sample and get TypeScript interfaces or types you can copy into your code, with nested objects, arrays and optional keys handled for you.
Loading the tool…
Example#
Given this JSON:
{"id":1,"name":"Ada","tags":["a"],"profile":{"url":null}}the tool produces:
export interface Root {
id: number;
name: string;
tags: string[];
profile: Profile;
}
export interface Profile {
url: null;
}How it works#
The tool reads your JSON, infers a type for every value and prints declarations. Strings, numbers, booleans and null map to string, number, boolean and null. Each object becomes a named declaration, named after its property in PascalCase, so user_profile becomes UserProfile. Arrays become T[]; when an array holds different kinds of values the type is a union such as (number | string | null)[]; an empty array becomes unknown[].
Objects inside an array are merged into one declaration. A key missing from some items becomes optional (marked with ?) when that option is on, and a key that is null in some items and a value in others becomes T | null. Names that collide get a number suffix, identical shapes reuse one declaration, and keys that are not valid identifiers, such as content-type, are quoted. You can choose interface or type, add or remove export, and mark properties readonly.
Assumptions#
- The sample is representative: the types describe only the data you paste.
- The JSON is at most 1 MB and nested no deeper than 50 levels.
- Numbers stay number; there is no split into integers and decimals.
Use cases#
- Typing the response of a REST API after copying a sample from the docs or the network tab.
- Typing a configuration file or a fixture.
- Getting a starting point to refine by hand.
Limitations#
The output is only as good as the sample. A field that is sometimes missing in real data but present in your sample will not be optional. Dates stay string, string enums and literal types are not inferred, and the generated types do not validate data at runtime; for that you need a schema validator. If the JSON is invalid, the tool shows the line and column of the problem. Your JSON is processed in your browser and is not sent anywhere.