/tools/json-to-typescript

JSON to TypeScript Converter

Generate interfaces or type aliases with nested declarations, optional properties, unions, and explicit nulls.

Options
Ready. Paste valid JSON or choose a file to infer TypeScript types locally.

JSON sample

TypeScript output

Back to input

Generate TypeScript types for date strings

Generate an interface from this API sample with the root type name Account:

{"created_at":"2026-11-26T09:00:00Z"}

The field is created_at: string. JSON transports the timestamp as text. Parse or validate it at the application boundary if the application needs a date object. Include representative array items when generating optional properties and unions.

/usage

How to convert JSON to TypeScript

  1. Paste representative JSON, drop a file, or load the sample response. If needed, check it first in the online JSON Viewer & Formatter.
  2. Choose interfaces or type aliases, exports, optional markers, and readonly properties.
  3. Generate, review the inferred contract, then copy or download the .ts file.

Generate interfaces with optional and nullable fields

Paste this synthetic API response, keep the root type Root, choose interfaces, and leave exports and optional markers enabled. Then select Generate TypeScript.

{
  "users": [
    {
      "user-id": 42,
      "label": null
    },
    {
      "user-id": 43,
      "label": "Ada"
    },
    {
      "user-id": 44
    }
  ]
}

The complete generated declarations are:

// Generated from JSON by Data Demon. Review inferred optional and nullable fields.

export interface Root {
  users: User[];
}

export interface User {
  "user-id": number;
  label?: string | null;
}

label? is optional because one sampled user has no label key. string | null preserves the other observed values. The quoted "user-id" keeps the JSON property spelling; read it with user["user-id"]. All three objects contribute to inference, not just the first one.

These declarations describe the sample, not every future response. A TypeScript assertion does not validate incoming JSON at runtime. Add representative items when an empty array gives no element evidence. For runtime Python models from the same sample, see JSON to Pydantic.

/inference

Useful TypeScript from real API samples

All array objects contribute

The converter merges every object sample in an array. Properties missing from some samples can become optional, while observed null values remain explicit null unions.

Mixed values remain unions

Unlike a first-item-only generator, differing string, number, boolean, object, array, and null evidence is retained as a TypeScript union instead of silently discarded.

Safe property and type names

Nested type names are deterministic and collision-safe. Property keys that are not valid TypeScript identifiers are quoted so their original JSON spelling remains exact.

Compact, bounded inference

One shared inference core records types and field occurrence counts rather than retaining duplicate values. Work runs off the main thread and is bounded by input, traversal, depth, schema, and output limits.

/faq

JSON to TypeScript questions

Is my API response uploaded?

No. JSON parsing, inference, and TypeScript emission happen in a dedicated browser worker. Input and generated types are not sent to Data Demon.

Should I choose an interface or type alias?

Interfaces are convenient for extendable object contracts. Type aliases are useful for a consistent alias-based style and are required automatically when the JSON root is an array, scalar, or union.

Why does an empty array become unknown[]?

An empty array provides no element evidence. Add a representative item to the sample or replace unknown with the intended domain type after generation.