JSON to TypeScript Converter

Turn a JSON sample into TypeScript interfaces or type aliases, with nested types and optional fields.

export interface User {
  id: number;
  name: string;
  email: null;
  roles: string[];
  profile: Profile;
  posts: Post[];
}

export interface Post {
  title: string;
  tags: (string | unknown)[];
  draft?: boolean;
}

export interface Profile {
  website: string;
  followers: number;
}

Keys missing from some array items become optional. A field holding both values and null shows as a union.

How to use

1

Paste a representative JSON sample into the input.

2

Name the root type and choose interface or type alias.

3

Copy the generated declarations into your project.

Example

Optional field from an array

draft appears in only one array item, so it is optional.

Input
{"posts":[{"title":"A"},{"title":"B","draft":true}]}
Output
export interface Root {
  posts: Post[];
}

export interface Post {
  title: string;
  draft?: boolean;
}

Frequently Asked Questions

No. Types are inferred from the one sample you paste, so a field that is sometimes a string and sometimes a number only shows both if both appear. Review the output against the API documentation.

Explore

Connected career roadmaps, algorithmic problems, and real-world curricula related to JSON to TypeScript Converter.