Skip to main content

JSON to TypeScript Converter

Convert a JSON sample into TypeScript interfaces or type aliases. Infers primitive, array, and nested-object types, merges arrays of objects into one interface with optional keys, and lets you name the root type.

Input

Name for the top-level interface/type. Converted to PascalCase.

How JSON null is typed. Empty arrays always become unknown[].

Output

TypeScript output
 
Was this helpful?

Guides

Paste a JSON sample and get ready-to-use TypeScript interfaces or type aliases describing its shape. The converter walks your JSON, infers a type for every value, and names nested structures for you — no manual typing, no guesswork. It's the fastest way to turn an API response, config file, or fixture into typed code.

What it does

The tool reads your JSON and produces matching TypeScript definitions:

  • Primitives map to string, number, and boolean.
  • Nested objects become their own named interface, referenced by the parent (e.g. address: Address).
  • Arrays of primitives become T[] — and heterogeneous arrays become a union, like (number | string)[].
  • Arrays of objects collapse into a single interface that merges every key seen across the elements. Any key missing from at least one element is marked optional with key?:.
  • null values widen to null (or undefined, your choice) instead of breaking the output.
  • Empty arrays become unknown[], since there's nothing to infer from.

How to use it

  1. Paste or type your JSON into the input box.
  2. Set the root type name — this names the top-level interface (default Root, converted to PascalCase).
  3. Choose the output style: interface or type alias.
  4. Pick how null values should be typed (null or undefined).
  5. Copy the generated TypeScript, or download it as interfaces.ts.

Output updates automatically as you edit, so you can tweak the JSON and watch the types change in real time.

Which should I choose — interface or type?

Interfaces are conventional for object shapes and support declaration merging; type aliases are handy when you want to compose or export the shape alongside unions and utility types. The generated members are identical, so pick whichever fits your codebase. You can switch between them at any time.

How are arrays of objects handled?

Every object in the array is scanned and their keys are merged into one interface. A key that appears in some but not all elements is made optional (key?:). This is what you usually want for real-world API arrays where records aren't perfectly uniform.

What happens with mixed or empty arrays?

A mixed array like [1, "two"] produces a union element type: (number | string)[]. An empty array has no members to inspect, so it becomes unknown[] — safe and explicit, and easy to narrow later.

Does it handle deeply nested JSON?

Yes. Each nested object gets its own interface named after its key, and those interfaces are emitted alongside the root type so the whole structure is fully typed.

Privacy

This converter runs entirely in your browser. Your JSON is parsed and transformed on your device — it is never uploaded to a server, logged, or stored. You can use it with sensitive payloads and work offline once the page has loaded.

jsontypescriptinterfacetypedevelopercodegen

Part of a workflow

All collections

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.