JSON to TypeScript Interface

Paste a sample API response or config object and get TypeScript declarations for it. Nested objects get their own named interfaces, arrays of objects are merged so properties missing from some items become optional, and keys that are not valid identifiers are quoted.

Data Formats Runs in your browser

Generate TypeScript Types

How to Use the JSON to TypeScript

  1. Paste a representative JSON sample.
  2. Set the root type name and choose interface or type alias, export and optional/readonly options.
  3. Press Generate.
  4. Copy or download the declarations and adjust names as needed.

About This Tool

Front-end and Node.js developers typing API responses, and anyone adding TypeScript to an existing JSON-based project.

Input: JSON  ·  Output: TypeScript (.ts).

Features and Limitations

Features

  • Merges all items of an array, so optional properties are detected.
  • Union types for mixed values, such as string | null.
  • Reuses one interface for identical shapes.
  • Quotes non-identifier keys like "first name".

Limitations

  • Types are inferred from one sample; values that are null or empty arrays in the sample become null or unknown[].
  • Dates and enums cannot be detected from JSON and appear as string or number.
  • Names come from keys with a simple singular rule (orders → Order) and may need editing.
  • Results are computed in your browser; nothing you enter is sent to a server.

Frequently Asked Questions

Why is a property typed as null?

The sample only contains null for it. Provide a sample with a real value, or edit the type to string | null.

How are optional properties detected?

When objects in the same array do not all have a key, that key is marked with ?.

interface or type?

Both describe object shapes. Interfaces can be extended and merged; type aliases can also express unions. Pick whatever your code base uses.

Is my JSON sent to a server?

No. Types are generated in your browser.

Related Tools

More like this: all Data Formats tools, all Developer & Web tools or the TinySandy home page.