JSON to TypeScript

Paste JSON and generate TypeScript interfaces: nested objects become their own interfaces, keys missing from some array items become optional, and mixed arrays become union types.

Developer Tools 100% in your browser

How to use

  1. Paste JSON into the input box.
  2. Set the root interface name if you want something other than Root.
  3. Click Generate TypeScript.
  4. Copy the interfaces into your project.

Example

Input: {"user":{"name":"Ada","tags":["a","b"]}}

Output: export interface User { name: string; tags: string[]; } · export interface Root { user: User; }

How it works

The JSON is walked recursively: every object becomes an interface, nested objects become their own interfaces, and arrays of objects merge into a single interface for the element type. A key missing from some objects in an array becomes optional (?), and arrays of mixed primitives become union types.

Object → interface with one field per key. Array of objects → element interface named from the singular field name ('items' → Item). Mixed array → union type, for example (boolean | number | string)[].

Worked example

{"user":{"name":"Ada","tags":["a","b"]}} produces interface User with name: string and tags: string[], and interface Root with user: User.

Edge cases to know

  • Input must be valid JSON: no comments, no trailing commas, no single quotes.
  • Array element interfaces are named from the singular field name; unusual plurals may be guessed wrong.
  • All numbers become 'number' and empty arrays become 'unknown[]' — refine these by hand.

Limits & compatibility

  • Input must be valid JSON: no comments, no trailing commas, no single quotes.
  • Array element interfaces are named from the singular field name ('items' → Item); unusual plurals may be guessed wrong.
  • All numbers become 'number' and empty arrays become 'unknown[]' — refine these by hand.

Privacy

Conversion runs locally in your browser. Your JSON — including any tokens it contains — is never sent to a server.

Related tools

FAQ

Questions about JSON to TypeScript

What does it generate for nested objects?

Each nested object becomes its own interface. For example, {"user":{"name":"Ada","tags":["a","b"]}} produces interface User with name: string and tags: string[], and interface Root with user: User.

What happens when some objects in an array are missing a key?

The key becomes optional (?). For example, if one object in an items array has a name and another does not, the generated Item interface has name?: string.

What are union types used for?

Arrays of mixed primitives. For example, [1, "two", true] becomes (boolean | number | string)[], because no single type covers all the values.

What must I fix by hand after generating?

All numbers become 'number' and empty arrays become 'unknown[]' — refine those where you need a narrower type. Interface names for array elements are guessed from the singular field name ('items' → Item), which can be wrong for unusual plurals.