Skip to main content
Tools

JSON to TypeScript

Generate TypeScript interfaces or type aliases from sample JSON, merging array items into optional properties and union types.

Declare as

0 characters · 1 line

Types are inferred from the sample: properties missing from some array items become optional (?), and cases the sample does not show are not included.

How to use

  1. Paste a JSON sample, such as an API response, on the left, or click “Example”.
  2. Set the root type name, choose interface or type declarations, and whether to add export and readonly.
  3. The TypeScript types appear instantly on the right (below on phones). Click “Copy” or “Download” for a .ts file.

FAQ

Is my data uploaded?

No. The types are generated in your browser and your JSON never leaves your device, so pasting API responses with personal data is fine.

What if objects in an array have different properties?

All elements of an array are merged into one type: properties that appear only in some elements become optional (name?: string), and a property with different types in different elements becomes a union (number | string).

What type does null become?

By default it joins the union, as in string | null; a property that is only ever null is typed null. With “Make null properties optional”, it becomes name?: string instead, which suits APIs that use null for “no value”.

How are nested types named?

After the property, in PascalCase: user_profile becomes UserProfile. Array items use the singular, so items of users are called User, or get an Item suffix when there is no plural to remove. Objects with exactly the same structure share one type; different structures with the same name get a number (Item2).

Why are some property names quoted?

Names that are not valid JavaScript identifiers (with - or spaces, or starting with a digit) must be quoted, as in "first-name": string. Chinese property names are valid identifiers and stay unquoted.

What about big numbers and dates?

JSON only has numbers and strings, so numbers beyond the safe integer range are still number and date strings are still string. Change them to bigint or Date by hand if you need to.

Keyboard shortcuts

/
Search tools (on a tool page, goes to the homepage search)
?
Show this help
Esc
Close a dialog
Ctrl / ⌘Enter
Run the tool's main action (where supported)

While you type in a text field, / and ? are typed as usual.