Skip to content
TypeParser
All tools

JSON to TypeScript

Generate TS interfaces from a JSON sample.

beats quicktype.io edge: Optional/union inference + nested types
JSON
paste JSON
Guide

About JSON to TypeScript

Generate TypeScript interfaces from any JSON sample. Handles nested objects (inline interfaces by default), arrays of objects (one unified interface), optional fields (when keys differ between array items), and union types (when a field has multiple shapes). Output is ready to paste into your codebase.

What this tool replaces

The first 30 minutes of integrating with a new API: hand-typing TypeScript interfaces from the response. Curl the endpoint, paste here, get types, paste into your codebase. Saves a chunk of every integration.

What it generates

export interface User {
  id: number;
  name: string;
  email: string;
  tags?: string[];
  address: Address;
}

export interface Address {
  street: string;
  city: string;
  state: string;
  zip: string;
}

Nested objects become their own exported interfaces. Optional fields get ?. Arrays of mixed types collapse to unions.

Common workflows

Type a new API response. curl | jq → paste here → copy types → paste into src/types/api.ts. Compile-time confidence in seconds.

Update types after API change. Re-curl, re-paste, diff against existing types in Diff Checker, apply changes.

Bootstrap a new project. Have sample JSON for fixtures? Generate types from them as a starting point.

What this tool can’t infer

  • Date strings vs strings — JSON has no Date type, so ISO 8601 strings type as string. Add a brand or as cast in your code.
  • String enums — fields with limited values type as string unless you flip the enum-detection toggle.
  • Discriminated unions across many shapes — if your data has 5 variants but the sample only shows 2, you will need to extend by hand.

For deep schema work with constraints, switch to JSON Schema Validator for runtime validation alongside the static types.

Frequently asked questions

Inline or named nested types?
Toggle Inline for everything in one interface, Named for separate exported interfaces per nested object. Named is easier to refactor.
How is "optional" inferred?
In an array of objects, if a key appears in some items but not others, it becomes optional (?). Useful when sample data covers the variation; brittle when the sample is too small.
What about unions?
{ a: 1 } | { a: "x" } becomes { a: number | string }. For richer cases (different shapes), discriminated unions are produced when a field consistently differentiates the variants.
Does it support readonly / strict optional?
Toggle Readonly to mark every field readonly. Pair with strict tsconfig for fully immutable types.
Is the JSON sent anywhere?
No. Inference runs in your browser. Your sample data stays on the page.
How big a sample?
Better with more — 100+ items in an array gives reliable optional/union inference. With 1-2 samples, expect to refine the output by hand.

Related tools

Last updated: 2025-01-15