JSON to TypeScript Converter

Paste an API response and get ready-to-use TypeScript interfaces or type aliases, with nested types, optional fields and null unions inferred for you.

Runs in your browserNo sign-upNothing uploaded

TypeScript

How to use the JSON to TypeScript

  1. Paste a JSON sample, such as an API response, into the left box or open a .json file.
  2. Set the root type name (for example User or ApiResponse).
  3. Choose interface or type declarations and toggle export, readonly or all-optional fields.
  4. Pick unknown (safer) or any for values that the sample cannot reveal, such as empty arrays and nulls.
  5. Copy the generated code or download it as a .ts file.

How the types are inferred

  • Primitives: strings, numbers and booleans map to string, number and boolean.
  • Nested objects become their own named interfaces in PascalCase, so billing_address becomes BillingAddress.
  • Arrays of objects are merged into one item type, named in the singular: users gives User[]. A key that is missing from some items becomes optional (key?:).
  • Null values combine with the other values seen for that key: string | null. A key that is only ever null falls back to unknown or any.
  • Mixed arrays become union arrays such as (number | string)[].
  • Identical shapes are declared once and reused, and different shapes that would share a name get a numeric suffix.
  • Keys that are not valid identifiers, such as "first-name" or "2fa", are quoted.

interface vs. type

For plain object shapes the two are nearly interchangeable. interface declarations can be extended and merged, and give slightly clearer compiler errors. type aliases can also express unions and mapped types. Many teams use interfaces for API models and types for everything else; choose whichever your codebase or linter (@typescript-eslint/consistent-type-definitions) expects.

Get better types from your sample

Types can only be as complete as the sample. Paste a response that includes optional fields, or an array with several varied items, so the generator can detect optional and nullable keys. Values such as dates and enums arrive as plain strings in JSON; narrow them by hand afterwards, for example status: 'active' | 'disabled'. For runtime validation, pair the generated types with a schema library such as Zod.

Frequently asked questions

Is my JSON uploaded?
No. Types are generated by JavaScript in your browser. API responses containing tokens or personal data never leave your device.
How are optional properties detected?
When objects in the same array have different keys, keys missing from at least one object are marked optional with ?. With a single object every key is required, unless you tick All optional.
Should I use <code>unknown</code> or <code>any</code>?
unknown is safer: TypeScript makes you narrow the value before using it. any turns type checking off for that value. Use it only if you plan to refine the types later.
Why is an ISO date typed as <code>string</code>?
JSON has no date type, so dates are strings on the wire. If you convert them with new Date() after parsing, change the property to Date in your model.
Can it handle large or deeply nested JSON?
Yes. Generation is linear in the size of the input and runs locally, so multi-megabyte responses convert in well under a second.

Related tools