JSON to TypeScript Converter

Generate TypeScript interfaces from a JSON sample directly in your browser.

This tool runs entirely in your browser. Your files are never uploaded to a server.

interface Root {
  name: string;
  age: number;
  active: boolean;
  tags: string[];
  address: Address;
}

interface Address {
  street: string;
  zip: string;
}

What this converter does

Reads a JSON value and generates matching TypeScript interfaces: one interface per object shape found in the sample, with each field typed from the value it holds.

How to use it

Paste a JSON object, array or primitive value into the editor. A `Root` interface (or type alias, for a non-object root) appears immediately, along with one additional interface for every nested object shape.

Example

An object with a `name` string and a nested `address` object produces `interface Root { name: string; address: Address; }` plus a separate `interface Address { ... }` for the nested shape, named after the key it came from.

Type mapping

Strings become `string`, numbers become `number`, booleans become `boolean`, and arrays become `ElementType[]`. A property whose sampled value is `null` is typed as `null` — widen it manually to `T | null` once you know the field's real type.

Nested objects and arrays

Each nested object gets its own named interface, generated from its key (for example `addresses` becomes an `Address` interface for its array items). If two different keys happen to produce structurally identical objects, each still gets its own interface rather than being merged into one.

Limitations

The generated types describe only the one JSON sample provided — a field that's a string in your sample but a number elsewhere in your real data won't be caught. Arrays of objects are typed from their first item only, and generated interface names may collide with reserved TypeScript keywords in unusual cases.

Privacy

Parsing and code generation both run locally in your browser. The JSON you paste and the TypeScript you generate are never uploaded.

Frequently Asked Questions

Does this validate my JSON against a schema?
No — it infers types from one sample value; it's a starting point for interfaces, not a JSON Schema or runtime validator.
What happens with arrays of objects?
The converter looks at the first item in the array to generate that object's interface; if later items have different fields, add them to the generated interface by hand.
Is my JSON sent to a server?
No — parsing and TypeScript generation both happen locally in your browser.