1. Home
  2. Developer
  3. JSON to TypeScript

JSON to TypeScript

Paste an API response and get types and a validation schema in one go.

Runs in your browser · No upload
A small sample cannot reveal optional keys. Wrap several responses in one array for better results.
null values
Types generated
5
Fields
20
Input size
0.4 KB
Result
export interface Root { id: number; name: string; email: string; isActive: boolean; createdAt: string; // ISO date shipping_address: ShippingAddress; tags: string[]; orders: Order[]; } export interface ShippingAddress { city: string; zip: string; coords: Coords; } export interface Coords { lat: number; lng: number; } export interface Order { id: number; total: number; couponCode?: null; items: Item[]; memo?: string; } export interface Item { sku: string; qty: number; }

How to use

  1. Paste a JSON sample into the input. A single API response works, and so does an array holding several of them.
  2. Choose TS interface, TS type, Zod or JSON Schema. All four are rendered from the same analysis.
  3. Adjust the root name, how null is handled, export, readonly and date detection.
  4. Copy the result or save it as a .ts file (.json for JSON Schema).

Inference rules

Input Result
Object A named interface. The root uses the root name; nested ones use the key in PascalCase (shipping_address becomes ShippingAddress)
Array of objects All elements are merged into one type. A key missing from some elements becomes optional (?)
Array item name The key made singular (users becomes User, categories becomes Category, addresses becomes Address). The rule is simple, so news becomes New | rename it if needed
Same key, different types A union (number | string)
Objects with the same shape One shared type, whatever the key order. A name clash gets a number, as in Item2
Empty array unknown[]
Mixed array (string | number)[]
null A union by default (string | null), or just null when every value is null. You can switch to an optional key or unknown
Key that is not an identifier Quoted ("first-name": string)
Date string A // ISO date comment for standard formats (z.string().datetime() in Zod)

The formats treated as dates are date-times with a zone, such as 2026-10-07T12:00:00Z or +09:00, and date-only strings such as 2026-10-07. A date-time without a zone would be rejected by datetime(), so it stays a plain string.

Example

For {"users":[{"id":1,"email":"a@x.com"},{"id":2,"phone":null}]}, phone appears only in the second element and email only in the first, so both become optional.

export interface Root {
  users: User[];
}

export interface User {
  id: number;
  email?: string;
  phone?: null;
}

Converting {"id":7,"name":"Kim","createdAt":"2026-10-07T12:00:00Z","tags":[]} to Zod with .int() turned on gives:

export const RootSchema = z.object({
  id: z.number().int(),
  name: z.string(),
  createdAt: z.string().datetime(),
  tags: z.array(z.unknown()),
});

Things to know

  • A small sample cannot reveal optional keys. With one response, every key in it looks required. Put several responses in one array and the missing keys and null values show up.
  • Empty arrays and values that are only null have no known type. They come out as unknown[] and null, so fill in the real type yourself.
  • Numbers are not split into integer and float. TypeScript says number; only in Zod can .int() be added, and only when every sampled value is an integer.
  • interface vs type: for plain object shapes they are nearly the same. An interface can be extended later under the same name, while a type shares syntax with unions and tuples.
  • Why Zod: TypeScript types exist only at compile time, so they cannot stop a server response from changing shape. Calling parse on a Zod schema checks the shape at runtime, and z.infer gives you the same type.
  • JSON Schema output follows draft 2020-12. Optional keys are left out of required, and nested objects go into $defs.
  • Input is limited to 2 MB and 64 levels of nesting.

To check syntax first, use the JSON Formatter. To change format, try JSON to YAML or JSON to CSV. To see how two responses differ, use JSON Diff.

The JSON you enter is processed in your browser only and is never sent to a server.

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.