Skip to content

JSON to TypeScript

Generate TypeScript interfaces, Go structs or Python dataclasses from JSON.

Language
Use type alias type X = {…}
JSON sample
TypeScript definitions

Paste a JSON sample to generate type definitions.

About the JSON to TypeScript

Paste a JSON sample and get the matching TypeScript interface, Go struct, or Python dataclass. Hand-writing types for an API response is mechanical work that is easy to get subtly wrong — this infers the shape for you, including which fields are optional and which can be null.

How to use it

  1. 1 Paste a representative JSON response into the input.
  2. 2 Pick the target language: TypeScript, Go, or Python.
  3. 3 Name the root type — nested types are named after the keys that hold them.
  4. 4 Copy the generated definitions straight into your project.

What it does

  • TypeScript interfaces or type aliases
  • Go structs with correct json struct tags
  • Python dataclasses with typing annotations
  • Merges every element of an array, so fields missing from some objects become optional
  • Infers nullable types when a value is sometimes null
  • Names nested types from their key, and singularises array element names

Frequently asked questions

Is my JSON sent to a server?

No. Every calculation happens locally in your browser using JavaScript. Nothing you paste is uploaded, logged, or stored on a server, which makes the tool safe to use with production data, credentials, and customer records.

How does it decide a field is optional?

It merges the shapes of every object in an array rather than looking only at the first one. If a key appears in some elements but not others it is marked optional — `b?: number` in TypeScript, `omitempty` in Go, a `None` default in Python. Generators that sample only the first element silently produce types that break on the second.

What happens with an empty array?

There is nothing to infer from, so the element type becomes `unknown[]` in TypeScript (`interface{}` in Go). Paste a sample that includes at least one element to get a real type.

Why did a field come out as unknown?

The same position held genuinely different types across samples — a number in one element and a string in another, for example. Rather than invent a union that the target language may not express cleanly, the generator falls back to the permissive type so you can decide.

Are the generated types safe to trust at runtime?

No — and this matters. Types generated from one sample describe that sample, not the API contract. They give you editor autocomplete, not runtime guarantees. If the data crosses a trust boundary, validate it at runtime with a schema library such as Zod or Valibot.