Skip to content
XUtilHub

JSON to TypeScript – Interface & Type Generator

Convert JSON to TypeScript interfaces or type aliases. Nested objects become their own types, and optional and nullable fields are detected from your data.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Code

About the JSON to TypeScript

Paste a JSON sample to get ready-to-use TypeScript interfaces. Every nested object gets its own named type, arrays are typed by their contents, and fields missing from some items are marked optional.

Key features

  • Interfaces or type aliases, exported and ready to import
  • A separate named type for every nested object
  • Optional (?) fields detected across array items
  • Nullable values typed as T | null
  • Keys like "first-name" quoted correctly
  • Optional readonly modifiers

Stop writing API types by hand

Typing an API response field by field is slow and error-prone, and it drifts out of date. Paste a real response and get accurate TypeScript types in a second, then import them across your front end or Node.js code for autocomplete and compile-time checks.

Example

{ "id": 7, "name": "Ada", "tags": ["admin"], "address": { "city": "London" }, "manager": null }
export interface Root {
  id: number;
  name: string;
  tags: string[];
  address: Address;
  manager: unknown;
}

export interface Address {
  city: string;
}

Type mapping

JSONTypeScript
"text"string
42, 3.14number
trueboolean
[...]T[]
{...}named interface
null alongside a valueT | null
missing in some itemsfield?: T
unknown / mixedunknown

Using the types

import type { Root } from "./types";

const res = await fetch("/api/user");
const user = (await res.json()) as Root;

Tips

  • Name the root after your data (e.g. User, Order) with the Root name option.
  • Use several array items so optional fields are detected.
  • Turn on readonly for immutable data, such as Redux or React state.

Using plain JavaScript? Try JSON to JavaScript for JSDoc types. Need runtime models in other languages? See JSON to Python, JSON to C# and JSON to Go.

How to use the JSON to TypeScript

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The TypeScript appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

Interface or type alias: which should I choose?

Both describe object shapes. Interfaces can be extended and merged, and are the common default for data models. Type aliases are needed for unions and mapped types. For JSON models either works.

How are optional fields detected?

When your JSON contains an array of objects, a key that's missing from some items is marked optional with ?. Include several representative items for the most accurate result.

What becomes 'unknown'?

Values whose type can't be inferred: null with no other examples, empty arrays, or arrays mixing different types. Replace unknown with the real type once you know it.

Does it validate data at runtime?

No. TypeScript types are erased at compile time. For runtime validation, pair the types with a library such as Zod, Valibot or io-ts.

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools