JSON to TypeScript converter

Convert JSON to TypeScript interfaces: paste JSON, such as an API response. Nested objects become named types, identical shapes are shared, and keys missing in some array items become optional.

JSON

TypeScript

Waiting for input

What you get

How each result is checked

  1. The generated code is compiled with the real TypeScript compiler in strict mode.
  2. Your JSON itself is type-checked against the root type. It must pass.

What can't convert exactly

  • Types can only describe what the sample shows. A field that is null in every sample is typed as null; add a sample with a real value for a better type.
  • Paste an array with several records to detect which fields are optional.
  • Numbers are typed as number. Use the Zod converter if you need to check whole numbers at runtime.

Questions

How are nested types named?

After their key, made singular for arrays: an "addresses" array gives an Address type. Objects with the same shape share one type.

Can I keep everything inline?

Yes. Set "Nested objects" to Inline.

How do I convert JSON to TS interfaces?

Paste a sample of your JSON. The page will generate TypeScript interfaces from JSON for the whole document and for every nested object, then checks that your JSON type-checks against them. Choose "type" in the options if you prefer type aliases.

How do I create a TypeScript type from an API response?

Copy the JSON response (from your browser’s network tab, curl or Postman) and paste it here. You get a JSON to TS interface for the response and every nested object. Paste an array of several items to find out which fields are optional; a field that is null in your sample is typed as null until a sample shows its real type.

Should I use interface or type?

Both work the same for JSON data. Interfaces are the default; choose "type" in the options for type aliases, for example if your project’s lint rules prefer them.

How do I convert JSON to TypeScript online?

Paste your JSON or open a file on the left (or click Example). The TypeScript appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.

Can the TypeScript output be wrong?

Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.