JustRandom

JSON to TypeScript Converter

Generate interfaces and type aliases from JSON.

Generate TypeScript from JSON

Paste sample JSON and generate TypeScript models locally in your browser.

Use an object or an array of objects for model inference.

TypeScript options

Generated code

Generated code will appear here.

Convert JSON to TypeScript

Turn a representative JSON object or an array of objects into TypeScript declarations without sending the sample to a server. The converter infers primitive values, arrays, nested objects, and fields that are missing from some array items.

Choose interfaces for declarations that can be extended or type aliases for a compact object type. The same inferred model powers both styles, so changing the output style does not change the detected fields.

TypeScript output and options

Nested JSON objects become named TypeScript declarations instead of loose object values. Property names can be normalized to camelCase, and exported or readonly declarations can be generated when those constraints fit the project.

Optional properties represent fields missing from some object samples. Nullable properties preserve observed null values with a union when nullable output is enabled; the two concepts remain separate.

TypeScript conversion example

Example JSON input:

{
  "account_id": 7,
  "profile": {
    "display_name": "Ada"
  },
  "roles": ["admin", "editor"]
}

Generated TypeScript output:

export interface RootModel {
  accountId: number;
  profile: RootModelProfile;
  roles: string[];
}

export interface RootModelProfile {
  displayName: string;
}

How to generate TypeScript code

  1. Paste a JSON object or an array of similar objects.
  2. Enter the root interface or type name.
  3. Choose interface or type alias output and adjust export, readonly, optional, nullable, and property-name options.
  4. Generate the TypeScript, then copy it or download the .ts file.

Frequently asked questions

How is JSON converted to a TypeScript interface?

The converter inspects sample values to infer TypeScript property types, then creates an interface for the root object and additional interfaces for nested objects.

What is the difference between an interface and a type alias?

Both outputs describe the same inferred object shape. Interfaces use interface declarations and are designed for extension and declaration merging, while type aliases use object type syntax and can fit codebases that standardize on type.

How are nullable values handled?

When a field is null in one of the samples, nullable output can add a null union to its inferred non-null type. Missing fields are tracked separately as optional properties.

How do nested objects become nested types?

Each nested object receives a stable name based on its parent model and JSON key. The parent property then references that generated declaration.

Is my JSON uploaded?

No. Parsing, inference, generation, copying, and downloading all happen in the browser. Input and generated TypeScript are not stored between sessions.

Private browser-based conversion

Your JSON input, field names, root model name, and generated TypeScript source stay in this browser. They are not sent to a backend, added to the URL, or saved in local storage or cookies.

Related tools

Compare another language-specific converter that uses the same local JSON inference engine.

Back to JSON to Code overview