Skip to content
</>Inblix Dev ToolsAll tools

JSON to TypeScript Converter Online

Paste an API response and get back a TypeScript interface you can paste straight into your types file. Nested objects, arrays of objects, and nullable fields are all inferred.

How it works

Hand-writing types from a JSON response is tedious and error-prone, and it drifts out of date the moment the API changes. Generating the interface from the payload you actually received gives you a starting point that matches reality rather than the documentation, which is frequently out of date.

Arrays get special treatment. An array of objects is emitted as a single interface whose members are the union of every object in the array, so a heterogeneous array produces a single type describing the fields observed rather than a union of separate types. If the first element of an array of objects is missing a field that later elements have, the first non-null value wins — this avoids collapsing a useful type to `any` just because one record was sparse.

The generated property names are quoted when they are not valid JavaScript identifiers. A key containing a space, a hyphen, or starting with a digit becomes `"content-type": string` rather than being emitted unquoted and failing to compile.

Scalar types map directly: strings to string, numbers to number, booleans to boolean, and null to null. An object nested inside another becomes an inline object type, and an object with no keys at all becomes Record<string, never> so it stays assignable rather than becoming an empty interface that nothing can satisfy.

This produces a starting point, not a finished type. You will normally want to replace inferred `unknown` and `Record<string, unknown>` with your own domain types, and to mark fields that are genuinely optional once you know the API guarantees them.

Use the JSON to TypeScript Converter

TypeScript
Paste json on the left to see the result.

Try an example:

Runs entirely in your browser — nothing you paste is uploaded or logged.

Worked examples

Real input and the exact output this page produces.

Example 1

JSON

                      {"id":1,"name":"Ada","active":true}
                    

TypeScript

                      export interface Root {
  id: number;
  name: string;
  active: boolean;
}
                    

Example 2

JSON

                      {"items":[{"id":1},{"id":2}]}
                    

TypeScript

                      export interface Root {
  items: {
    id: number;
  }[];
}
                    

Frequently asked questions

Why do some fields come out as unknown?

A field whose value is null in every record you pasted cannot be inferred, so it is typed as unknown or null. Fill in the real type once you know it.

Can I generate a type alias instead of an interface?

Yes. Rename the generated interface to whatever you prefer — this page is a starting point that you are expected to edit.

How are special property names handled?

Keys that are not valid JavaScript identifiers are emitted as quoted string keys, which is valid TypeScript and compiles correctly.

Others doing similar work.