JSON to TypeScript Interfaces

Generate TypeScript interfaces or type aliases from a JSON sample, with optional keys, null unions and nested types inferred from arrays. Free and private.

Keys missing from some array items become optional (?), null values become "| null", values that are only ever null become unknown.

Runs entirely in your browser. Your data is never uploaded.

Related Tools

View All

What is JSON to TypeScript?

Paste an API response or config sample and get ready-to-use TypeScript interface (or type) declarations. Nested objects become separate exported types, keys missing from some array items become optional and null values become union types.

How to use JSON to TypeScript

  1. Paste a JSON sample into JSON input (or click Load sample / Open file).
  2. Set the Root type name (default Root).
  3. Choose Output style: interface or type alias.
  4. Copy the generated TypeScript code or Download it as a file.

Example

Input
{"id":1,"name":"A","tags":["x"]}
Output
export interface Root {
  id: number;
  name: string;
  tags: string[];
}

When to use JSON to TypeScript

Use it to type fetch responses, fixtures or config files quickly. A single sample cannot reveal every case: string enums, unions of object shapes or date strings stay plain string/merged types, so review the result and refine it, or use a JSON Schema based generator for contracts.

How JSON to TypeScript works

The sample is walked recursively and every position collects the types it has seen. Arrays of objects are merged into one type: a key missing from some elements becomes optional, a key that is null somewhere becomes nullable, integers mixed with decimals become a floating-point type, and anything else that mixes types falls back to a dynamic type. Nested objects become their own named types (PascalCase of the key, array keys singularized: orders → Order), with numeric suffixes when names collide. TypeScript output maps integers and decimals to number, strings to string, booleans to boolean, arrays to T[], nullable values to T | null and dynamic values to unknown. Keys that are not valid identifiers are quoted ("first-name": string).

Common Use Cases

  • Type a REST API response before writing a client
  • Create interfaces for a JSON config file
  • Convert test fixtures into typed objects
  • Bootstrap types for a third-party webhook payload

FAQs

Why is a property typed as unknown?

Its value was null in every sample (or arrays were empty), so no real type could be inferred. Add a sample with a real value or edit the type by hand.

How are optional properties detected?

When the top-level value or a nested key is an array of objects, a key present in only some of the objects is marked with ?.

Does it produce runtime validation?

No, it only emits type declarations, which disappear at compile time. Use a validator such as a JSON Schema if you need runtime checks.

Good next steps

Explore more categories