Code · Made a little simpler

JSON to TypeScript Interface

Convert sample JSON into named TypeScript interfaces or aliases with optional properties, nested objects and mixed array items. Download the .ts file.

Free to useNo account neededProcessed on your device
Your workspaceProcessed on your device

Add this tool to your website

Paste this code into your page to add the tool and a visible ToolMellow credit link.

HTML embed code
Preview embed

JSON to TypeScript Interface: how to use it

  1. Paste representative JSON or open a local UTF-8 file.
  2. Enter a root declaration name and choose interfaces for objects or type aliases. Use the optional-property setting if the input represents a partial response.
  3. Generate TypeScript, review the inferred unions and properties, and copy or download types.ts.

Limits and notes

Runs on this device with up to 4,194,304 input and output characters, 4 MiB per file, 128 nested levels and 500,000 JSON tokens. JSON numbers infer TypeScript number and JSON strings infer string. Declarations describe the observed structure and provide compile-time types.

How your privacy works →

JSON to TypeScript Interface: common questions

Can I convert a JSON array at the root?

Yes. The root is a type alias for an array or primitive. Nested object declarations use your selected style.

How do missing properties and null differ?

A property missing from any sampled object at that position is marked optional. A null value is present and contributes null to the property's type.

Are property names such as order-id safe to use?

Keys with punctuation, spaces or other characters outside the supported bare spelling are quoted. They keep the same JSON property name.

Guides