JSON to TypeScriptLocal interfaces and type aliases
en

AppHelp

Convert JSON to TypeScript types

Paste one JSON object or an array of samples and get editable TypeScript definitions instantly, with optional-key inference, naming controls, copy, and .ts download.

JSON type generation workspace

Paste a JSON sample and get editable TypeScript definitions immediately.

Runs locally
174 characters16 lines
TypeScript output
array2 types4 properties
export type Root = RootItem[];

export interface RootItem {
  id: number;
  name: string;
  roles: string[];
  nickname?: string;
}

Types are inferred from the sample values. Review optional, nullable, and empty-array fields before using the output in production.

Common tasks

  • json to typescript
  • json to typescript converter
  • json to typescript interface
  • generate typescript from json
  • json to ts online
  • typescript interface generator
  • json array to typescript
  • json to type alias
  • free json to typescript tool
  • browser local typescript generator

Quick answer

Paste valid JSON to generate TypeScript interfaces or type aliases immediately. Nested objects become named declarations, arrays are merged across samples, missing keys can become optional, mixed values become unions, and null remains explicit; all processing stays in your browser.

How to use

  1. 1. Paste representative JSONUse a real but non-sensitive API sample. Include multiple array items when fields vary so optional keys and unions can be inferred.
  2. 2. Name and shape the outputChoose the root type name, interface or type syntax, array notation, optional-key behavior, readonly fields, and formatting preferences.
  3. 3. Review inferred edge casesCheck empty arrays, null values, mixed primitive types, date strings, and converted property names against the actual API contract.
  4. 4. Copy or downloadCopy the declarations or download types.ts, then add domain-specific comments, enums, branded identifiers, or runtime validation separately.

Examples

Simple object

Input
{"id":1,"name":"Ada","active":true}
Output
export interface Root { id: number; name: string; active: boolean; }

Optional array key

Input
[{"id":1},{"id":2,"nickname":"lin"}]
Output
export interface Root { id: number; nickname?: string; }

Enable missing-key inference so properties absent from some samples receive ?.

Nullable field

Input
[{"score":9.5},{"score":null}]
Output
score: number | null;

Null is preserved rather than silently converted to any.

Common use cases

  • Bootstrap API response interfaces for a frontend project
  • Document webhook payloads and configuration files
  • Compare multiple sample objects before defining a contract
  • Create starter types for tests, fixtures, and data pipelines
  • Turn copied JSON examples into code-reviewable declarations

Edge cases

  • One sample cannot prove every optional field or possible enum value; arrays with varied objects provide stronger inference.
  • Empty arrays default to unknown[] or any[] because no element type is observable.
  • ISO-looking strings remain string unless the Date option is enabled, and runtime JSON still contains strings.
  • camelCase conversion changes property names and may require a mapping layer when API keys use snake_case.
  • Generated static types do not validate untrusted data at runtime; use a schema library when runtime checks are required.

Features

  • Instant JSON-to-TypeScript conversion without uploads
  • Interface or type-alias output with custom root names
  • Nested object, array, union, null, and optional-key inference
  • Readonly, semicolon, export, camelCase, Date, and array-style controls
  • Four realistic sample presets plus inline JSON errors
  • Copy generated code or download a ready-to-edit .ts file

Frequently asked questions

Does it generate interfaces or type aliases?
Both. Choose interface or type and the converter applies that style to generated object declarations.
How are optional properties detected?
When an array contains multiple objects, a key missing from some objects receives ? if optional-key inference is enabled.
How are null and mixed values handled?
Observed types are combined into unions, so a field seen as a number and null becomes number | null.
What type is generated for an empty array?
There is no sample element to infer, so the selected fallback produces unknown[] or any[].
Does generated TypeScript validate JSON at runtime?
No. TypeScript types are erased at runtime. Add a runtime schema or validator for untrusted responses.
Is my JSON uploaded?
No. JSON.parse, inference, copying, and .ts generation all happen locally in your browser.