Skip to content
snip tools

JSON to TypeScript interface generator

Generate TypeScript interfaces from JSON. Nested objects, arrays and optional fields are inferred. Runs in your browser.

Runs 100% in your browser
 

How to convert JSON to TypeScript

  1. Paste your JSON. Paste a JSON object or array — a sample API response works well.
  2. Name the root. Optionally rename the root interface.
  3. Copy the interfaces. Copy the generated TypeScript into your project.

How the shape becomes types

Typing an API response by hand is tedious and easy to get subtly wrong. This generator does the mechanical part: it walks a sample document and emits matching interfaces — an object becomes a named interface, a nested object becomes its own interface named after its key, and an array becomes a typed array (User[]). When an array holds several objects, it merges them, so a key that's present in some and absent in others is correctly marked optional with ?, and values with more than one type become a union like string | number.

Why the output is a starting point, not the final word

The important caveat with any sample-based generator: it can only describe the data it's shown. If a field is nullable but happens to be non-null in your sample, the inferred type won't know it's optional. If an enum-like string only ever shows one value here, you'll get string, not the literal union you might want. And an empty array can't reveal its element type, so it falls back to any[]. Treat the result as a fast, accurate scaffold of the shape you pasted — then tighten the types your API contract actually guarantees.

TypeScript or Go

This emits TypeScript interfaces, which lean on the language's structural typing, optional members and union types. If you're working in Go instead, the JSON to Go generator produces structs with the right field tags, and the JSON formatter is handy for confirming your sample is valid before you generate from it.

Frequently asked questions

How does it infer the types?
It walks your JSON and builds TypeScript interfaces: objects become named interfaces, arrays become typed arrays, and arrays of objects are merged into one interface. A key missing from some objects in an array is marked optional with ?.
How are nested objects named?
Each nested object gets its own interface named after its key (singularised for array elements), so users: [...] produces a User interface.
What about mixed or null values?
Mixed types become a union (e.g. string | number); a value that's only ever null becomes null. Empty arrays become any[].
Is my JSON uploaded?
No — inference runs entirely in your browser.