JSON formatter / validator

JSON to TypeScript types

Generate a TypeScript interface tree from a JSON sample to scaffold typed API clients in seconds.

local only

Format pair conversion

JSON to TypeScript conversion notes

Use this JSON to TypeScript generator when a third-party API, fixture file, or webhook payload arrives as raw JSON and you want a starting interface tree for typed code. The page infers a type for each property by inspecting the value, treating arrays as T[], collapsing optional fields by sampling the data, and producing a top-level interface with named nested interfaces for objects. It is meant as a scaffold rather than a contract: review the inferred types, narrow string unions where the values are bounded, and tighten optional fields by checking the API documentation before you commit them.

Source

{"id":42,"name":"Ada","tags":["admin","editor"],"profile":{"verified":true,"joinedAt":"2026-04-12T08:00:00Z"}}

Result

interface Root {
  id: number;
  name: string;
  tags: string[];
  profile: Profile;
}

interface Profile {
  verified: boolean;
  joinedAt: string;
}
Inference rule
JSON null becomes null in the type, not undefined; JSON 1 and 1.5 both map to number
Date handling
ISO 8601 strings stay typed as string; cast to Date in the consuming code
Common pitfall
Single-sample inference can miss optional fields that appear on other API responses

Source: TypeScript handbook: Object Types, accessed 2026-05-06

FAQ

Why are dates typed as string instead of Date?

JSON has no native date type, so dates serialize as strings. Generated types reflect the wire format. Convert to Date in your code if needed (for example with z.coerce.date in Zod or new Date()).

How does the generator decide which fields are optional?

From a single sample it cannot. Every field present in the input becomes required. To capture optional fields, paste a union of representative samples, or mark fields optional manually after review.

Will the generator produce union types from string enums?

It produces string by default. If a field always takes a small set of values you control, narrow it manually to a string literal union (for example 'pending' | 'paid' | 'failed').