JSON to TypeScript
Turn an API response into nested types with arrays, unions and null values.
- 1Add input
- 2Adjust settings
- 3Get your result
Tool input and files are processed in this browser without being uploaded.
Before you start
Generate a TypeScript type alias or a top-level interface from a JSON response, including nested objects, arrays and null values. Fields missing from some objects in a sample array become optional; fields absent from the entire sample cannot be inferred. Large JSON numbers become number, so review precision requirements.
How to use this tool
- Choose Paste JSON or Choose a file, then provide one JSON object or array.
- Set the output name and choose a type alias or an interface. Interfaces require a top-level JSON object.
- Review optional fields, null values and number precision, then copy or download the .ts file.
Supported inputs and limits
Types describe this sample only. Optional fields are inferred only when they vary among objects in a sample array. Types do not validate runtime data.
Processing stays in your browser. Pasted text is limited to 1 MiB.
Worked example
Example input
{"id":1,"tags":["local",null],"active":true}Example options
{}Example output
export type Root = {
"id": number;
"tags": Array<string | null>;
"active": boolean;
};
When something does not work
Types describe the supplied sample. Check optional fields, other possible values, number precision and runtime validation against the actual API contract.
Frequently asked questions
Are files uploaded?
No. File bytes and input are processed in this browser.
Does the output include every optional field?
Fields missing from some objects in a sample array become optional. Fields absent from every sample, other possible values and business constraints still need the actual API contract.
Do TypeScript types validate runtime data?
No. Generated declarations support development-time checks. Your application still needs runtime validation and error handling where appropriate.
Documentation & further reading
Related tools
JSON formatting workspace
Format or minify strict JSON, sort object keys, and encode or decode strings while preserving raw number tokens.
Regex tester
Try a pattern and see what it matches in your text.
Compare text
See what changed, side by side.
HTML formatter
Format HTML indentation so its structure is easier to read.