Skip to content

JSON to TypeScript

Generate TypeScript interfaces from a JSON sample.

Input

What this tool does

Generate TypeScript interfaces from a JSON sample. Paste a payload and get strongly-typed interface declarations you can drop into a project — arrays infer item types, nested objects become their own interfaces, and nullable fields are emitted as a union with null. Powered by quicktype, runs entirely in your browser.

How to use it

Paste JSON (or load the example), pick a top-level type name, and read the TypeScript on the right. Switch to a different language at any time via the tabs above.

Input: {"id":42,"name":"devsmiths","createdAt":"2024-03-11T08:24:00Z","stars":1280,"public":true,"contributors":[{"login":"ada","commits":51,"admin":true},{"login":"linus","commits":33,"admin":false}],"homepage":null}

Output (TypeScript):

export interface Root {
    id:           number;
    name:         string;
    createdAt:    string;
    stars:        number;
    public:       boolean;
    contributors: Contributor[];
    homepage:     null;
}

export interface Contributor {
    login:   string;
    commits: number;
    admin:   boolean;
}

Limits and edge cases

  • Single-sample inference: every field present in your sample becomes part of the type. Fields absent from the sample don’t become optional automatically — toggle all optional in the options pane if every field should be nullable.
  • The generated code is a starting point. Naming follows each language’s idiom but you’ll often want to rename types and tighten unions by hand.
  • First generation takes 1–3 seconds while the quicktype engine downloads into the Web Worker. Subsequent generations are near-instant.
  • Output for non-TypeScript targets renders without syntax highlighting in the editor pane (CodeMirror language packs for Go / Python / Rust / etc. are not bundled to keep the page light). Copy / Download still produce the correct file content.
  • The input must be valid JSON — for trailing commas, single quotes, or comments, run the JSON Repair tool first; for a quick sanity check use the Validator.
  • Background reading: JSON to TypeScript in practice walks through the workflow end-to-end, including the rename / tighten step.

Frequently asked questions

Which languages does it support?
Eight: TypeScript, Go, Python, C#, Rust, Java, Swift, and Kotlin. Switch via the segmented tabs above — the URL changes to /json/types/<language> and the output regenerates in place.
Why is the first generation slow?
The quicktype engine (~700 KB) is loaded into a Web Worker on first use. After that it's cached for the rest of the session — subsequent generations are near-instant.
Is my JSON uploaded?
No. The generator runs entirely in a Web Worker in your browser. Nothing is sent to a server.
Can I use multiple JSON samples?
Not yet — the current build infers types from a single sample, so fields absent in the sample become required-with-the-observed-type. Multi-sample inference (union types, optionality detection across samples) is on the roadmap.
Does it generate serializers?
Where the target supports it: Go gets `json:` tags, Rust gets serde derives, Java gets Jackson annotations, C# gets attributes, Swift gets Codable conformance. TypeScript emits plain interfaces. Toggle 'all optional' if every field should be nullable.
The generated code isn't perfect — can I fix it?
Yes — treat the output as a starting point. Rename types, tighten unions, mark nullables explicitly. The generator is opinionated and conservative; humans always win on naming and intent.