JSON to TypeScript - Generate TypeScript Interfaces from JSON
Turn a JSON sample into TypeScript interfaces and type aliases. Paste JSON or choose a .json file, then copy or download the declarations. Your JSON stays in your browser.
- Free
- Runs in your browser
- No data upload
Only UTF-8 JSON files are supported. Files are read locally and never uploaded.
The root name is used for the top type. Nested object names come from their JSON keys.
Ready. No JSON leaves your browser.
Generated TypeScript
Your JSON input is not changed. The declarations describe the sample you provided, so review them against real responses before use.
How to convert JSON to TypeScript
Add your JSON
Paste a JSON sample or select a .json file. The file is read locally in your browser.
Generate types
Click Generate TypeScript. Objects become interfaces; arrays, unions and null are inferred from the sample.
Copy or download
Copy the declarations or save them as types.d.ts and use them in your project.
Paste JSON or choose a .json file, click Generate TypeScript, then copy the output or download types.d.ts. Optionally set a root type name and toggle the export keyword.
When to use this JSON to TypeScript converter
Bootstrap TypeScript types from a real API response instead of writing interfaces by hand. Nested objects and arrays are followed automatically, so a small sample can produce the full set of declarations.
Keep a client SDK or test fixture in sync with a backend payload: paste a fresh response and compare the generated shapes.
Document third-party JSON you consume, so editors and the TypeScript compiler can check the fields you read.
Prototype quickly: describe a configuration file or a webhook body, then refine the generated types by hand where the sample is incomplete.
How JSON values map to TypeScript
| JSON value | TypeScript | Notes |
|---|---|---|
| object | interface | Nested objects become their own interfaces, named from the key. |
| array of one kind | string[] | All elements share a single type. |
| empty array | unknown[] | An empty JSON array has no element information. |
| array of objects | Item[] | Elements are merged into one interface. |
| mixed array | (number | string)[] | A union of the observed element types. |
| string | string | Quoted text. |
| number | number | Integers and decimals both map to number. |
| boolean | boolean | true or false. |
| null | null | A key absent from some array elements becomes optional. |
Limitations
The output is a description of one sample, not a runtime validator. Keep these limits in mind:
One sample. Types are inferred from the JSON you paste. Fields that are absent from the sample cannot be inferred, and a value that appears once is treated as fixed.
Empty arrays. An empty array carries no element information, so it becomes unknown[]. Replace it with the real element type once you know it.
Merged objects. Array elements are merged into one interface; a key missing from some elements becomes optional. A single interface can misrepresent APIs that return genuinely different shapes for different elements.
Mixed arrays. Arrays that mix value kinds become a union, which is wider than the data may really be.
null. A null value maps to the null type. Nullable fields are not made optional unless the key is missing from some array elements.
Numbers and key order. There is no integer/float distinction, and object keys follow JavaScript property order (integer-like keys first), not necessarily the order written in the source.
For runtime checking, generate a schema (such as JSON Schema or Zod) instead and validate responses at the boundary. This tool only reports JSON syntax errors; it does not validate your data against a schema.
JSON to TypeScript FAQ
Is my JSON uploaded?
No. Pasted JSON and selected files are processed locally in your browser. Loading the page itself still makes ordinary website requests for HTML, styles and scripts.
Does the tool validate my JSON?
It reports JSON syntax errors from the browser's parser, but it does not check your data against any schema and it cannot confirm that a field type is correct.
Why is my empty array typed as unknown[]?
JSON does not record what an empty array would contain. Without at least one element there is no type to infer, so the converter uses unknown[] and leaves the decision to you.
How are arrays of different objects handled?
All object elements are merged into one interface. A property present in every element stays required; a property missing from some elements becomes optional.
Can I choose the root type name?
Yes. Set the root name field before generating. Nested interfaces are named from their JSON keys, and any invalid characters are converted to a safe identifier.
Is the generated code valid TypeScript?
The generated declarations are syntactically valid and compile on their own. Whether they match your real data depends on the sample you provided, so test against real responses.