JSON_TO_TS_V1

JSON to TypeScript

Paste any JSON — an API response, a fixture, a config file — and get clean TypeScript interface or type definitions. Object shapes inside arrays are merged, missing keys become optional, and mixed-type fields turn into unions.

Root name
Output
JSON input288 B
TypeScript output3 types · 299 B
export interface Root {
  id: number;
  name: string;
  active: boolean;
  roles: string[];
  address: Address;
  posts: Post[];
}

export interface Post {
  id: number;
  title: string;
  tags: string[] | unknown[];
  pinned?: boolean;
}

export interface Address {
  city: string;
  zip: string;
}
check_circleValid JSON
Lines
20
Types
3

How are nested types named?

Each nested object becomes its own named interface, derived from the surrounding key. So { "user": { "address": { ... } } } produces User and Address interfaces. Plural keys like items that hold an array become Item[] with a singular element type. Name collisions get a numeric suffix.

How are arrays handled?

When every item in an array is an object, the shapes are merged: the union of all keys becomes the field set, keys missing from some items are marked ?, and mixed value types become A | B. Mixed arrays (e.g. strings and numbers) produce a union element type. Empty arrays become unknown[] — there's no information to infer from.

What does AI Fix do?

When the input fails to parse, the AI Fix button routes your JSON through the same LLM that powers the chat assistant on this site. It strips comments, fixes trailing commas, re-quotes keys and strings, and balances brackets — streaming the repaired JSON back into the editor so the type generator can take over. Only the AI Fix call leaves your browser; the type generation itself stays local.

Is my data sent anywhere?

The type generator runs synchronously in your browser. The only network call is the optional AI Fix button, which forwards your JSON to an LLM for repair — skip the button to keep everything local.