JSON to TypeScript

Free JSON to TypeScript converter. Generate interfaces or types from JSON with nested objects, arrays and unions inferred automatically, copy the result, no signup.

Built and maintained by Shehzad Munir ·

JSON to TypeScript
Loading Loading JSON to TypeScript
Share

Typed models from real data

Convert any JSON into TypeScript interfaces or types instantly, with nested objects, arrays, unions and optional properties inferred automatically.

Hand-writing TypeScript interfaces to match an API response is tedious and error-prone. Paste a JSON payload and this tool walks the structure, generating a matching interface (or type alias) with correctly-typed fields, nested interfaces for objects, and array element types. Mixed arrays become union types, so your models reflect the data exactly.

Features

  • Generate interfaces or type aliases
  • Handles nested objects & arrays
  • Infers union types from mixed arrays
  • Optional properties for nulls
  • Custom root type name
  • Runs locally: code never uploaded

How to use JSON to TypeScript

  1. 1

    Paste JSON

    Drop in an object or array of data.

  2. 2

    Set options

    Choose interface or type, name the root, mark nullables optional.

  3. 3

    Review the types

    Nested interfaces are generated automatically.

  4. 4

    Copy

    Copy the TypeScript into your project.

Common use cases

  • Type an API response quickly
  • Generate models from a JSON fixture
  • Create interfaces for a config file
  • Bootstrap types for a new integration

Detailed guide

Tune the output to your style

Choose whether to emit interfaces or type aliases, name the root type, and optionally mark nullable fields as optional. The generated code updates live and is ready to paste into your project. It all runs in your browser, so private API payloads and internal schemas never leave your machine.

How types are inferred

The converter reads your JSON and maps each value to a TypeScript type: strings, numbers and booleans become string, number and boolean, nested objects become their own named interfaces, and arrays become typed arrays. When an array holds different kinds of values, the result is a union such as (string | number)[]. A null value becomes null, because the sample can't show what the field holds when it's set. Property names that aren't valid identifiers, like "first-name", are quoted so the output always compiles.

Getting accurate types from sample data

Inferred types are only as good as the sample. If a field is missing from some API responses, mark it optional with ? after generating, and if a field can be null in production, widen it to string | null. Use the fullest response you can find, ideally one where every optional field is present. For APIs you don't control, pair the generated types with runtime validation, for example Zod or io-ts, because TypeScript types disappear at runtime and won't catch a changed API. Dates arrive in JSON as strings, so convert them yourself if you need Date objects.

Frequently asked questions

How do I convert JSON to a TypeScript interface?

Paste your JSON and the tool generates a matching interface instantly, creating nested interfaces for objects and inferring array element types. Copy it straight into your code.

Does it handle nested objects and arrays?

Yes. Nested objects become their own named interfaces and arrays are typed by their elements. Arrays with mixed types produce a union like (string | number)[].

Can I get type aliases instead of interfaces?

Yes: toggle the option to emit 'type' aliases instead of 'interface' declarations, and rename the root type to suit your project.

Is my JSON uploaded anywhere?

No. Parsing and generation happen entirely in your browser, so sensitive payloads never leave your device.

How do I generate TypeScript interfaces from JSON?

Paste your JSON (for example an API response), give the root a name, and the tool infers types and produces ready-to-use interfaces, including nested objects and arrays. It runs locally, so real payloads stay private.

Does it handle nested objects and optional properties?

Yes. Nested structures become their own named interfaces, arrays get element types, and you can mark fields optional so the types match real, sometimes-missing data.

Can I output a type alias instead of an interface?

Yes. Choose interface or type output depending on your codebase's style; both produce accurate TypeScript from the inferred JSON shape.

From the journal

All articles →