Tools/JSON to TypeScript

JSON to TypeScript Converter

Convert JSON to TypeScript interface or type declarations instantly — optional fields detected automatically from null values.

JSON Input
TypeScript Output

Paste JSON and click Convert

Instant conversion

Handles nested objects, arrays, and null values in one click.

interface or type

Switch between interface and type alias output to match your codebase's style.

Optional-field detection

A null value in your sample marks the field optional and nullable in the output.

Related Tools

// more about this tool

Why use this tool

Hand-writing a TypeScript interface for an API response has the same failure mode as writing one for Dart: it's slow for a payload with a dozen fields, and a typo in a key name or a wrong primitive type doesn't get caught until something downstream breaks. This tool parses the JSON you paste in, infers a TypeScript type for each field, and generates interface or type declarations with optional fields detected automatically.

A nested object in your sample becomes its own named type, and a typed array becomes T[] rather than any[], so the output is as close to what you'd write by hand as the sample data allows.

How it works

  1. Paste a sample JSON response into the input panel — with every field populated, since a null sample can't reveal its real type.
  2. Set the root type name.
  3. Choose interface or type from the Output dropdown.
  4. Click Convert, then copy the generated declarations.

Example

Input

{ "id": 1, "name": "Bilal", "middleName": null }

Generated interface

interface User {
  id: number;
  name: string;
  middleName?: null;
}

FAQ

Does my JSON leave the browser?

No — parsing and generation both run client-side in JavaScript, exactly like every other tool on this site.

Does this generate readonly fields?

No, that's out of scope for this tool — every field is generated as a normal mutable property. Add readonly yourself afterward if your project's conventions require it.

interface vs. type — which should I pick?

Both describe the same shape for a plain object and are interchangeable for this use case; pick whichever your codebase already uses. interface supports declaration merging and is the more common choice for object shapes representing API data; type is required if you ever need unions or mapped types layered on top.

How are optional and nullable fields distinguished?

A field that's null in your sample gets a ? (optional) and a null member in its type, since a single sample can't tell you whether the field is sometimes absent, sometimes null, or both — marking it both covers either case safely.

Does it dedupe identical nested shapes into one type?

No — each nested object gets its own type named after its key, even if two different keys happen to produce identically-shaped objects. Rename or merge types by hand afterward if you want to share one type across fields.

What happens with an array that mixes types, like numbers and strings?

A mixed-type array falls back to unknown[] rather than guessing from only the first element, since picking one element's type would silently produce a type that's wrong for the rest of the array's contents.