Skip to content

JSON to Interface

Generate TypeScript interfaces from a sample JSON document, including nested objects.

TypeScript Interface

Paste your JSON on the left to instantly generate TypeScript interfaces.

What JSON to Interface does

Typing an API response by hand is tedious and error-prone, particularly when it is deeply nested. Pasting one real response and generating the shape from it is faster and reflects what the service actually returns.

The generator walks the document, emits an interface for the root, and creates a separate named interface for each nested object so the result stays readable.

  • Infer string, number, boolean, array and object types
  • Emit a separate named interface for each nested object
  • Quote keys that are not valid TypeScript identifiers
  • Copy the generated types straight into your editor

How to use JSON to Interface

  1. 1

    Paste a representative response

    Use a real payload with every optional field populated, since the generator can only see what is present in the sample.

  2. 2

    Read the generated interfaces

    The root type is emitted first, followed by an interface for each nested object.

  3. 3

    Copy into your project

    Copy the output and rename the root interface to something meaningful for your codebase.

  4. 4

    Review optional and nullable fields

    Mark fields that can be absent as optional yourself. A single sample cannot tell the generator which ones those are.

Example

A nested response and the types generated from it

Input

{
  "id": 7,
  "author": { "name": "Ada", "verified": true },
  "tags": ["release", "beta"]
}

Output

interface Author {
  name: string;
  verified: boolean;
}

interface RootObject {
  id: number;
  author: Author;
  tags: string[];
}

Limits and known behaviour

  • Types are inferred from one sample, so a field that happens to be null in your example cannot be typed and becomes `any`.
  • An empty array gives no information about its contents and is typed as `any[]`.
  • Nothing is marked optional. The generator cannot know from a single document which fields may be absent.
  • Union types are not produced. A field that is sometimes a string and sometimes a number is typed from the sample you provided.
  • Enum-like string fields become `string`, not a union of literals.
  • The root interface is always named RootObject; rename it after pasting it into your project.

Privacy and data handling

Runs entirely in your browser

  • Your input is processed by JavaScript running in this page. The tool sends no request anywhere, so nothing you paste is transmitted or logged by this site.
  • Nothing is saved between visits. Closing or reloading the tab discards whatever is in the fields.

Site-wide data handling, including analytics and advertising, is described in the privacy policy.

Frequently asked questions

How should I handle fields that are sometimes missing?

Add the question mark yourself after generating. A single sample cannot distinguish a field that is always present from one that happened to be present this time, and guessing would produce types that lie about the data.

Why is one of my fields typed as any?

Because its value was null or an empty array in the sample. Neither carries type information. Supply a sample where the field is populated, or write that one type by hand.

Does it generate types for other languages?

No, TypeScript interfaces only.