JSON to TypeScript Interface & Type Generator

ConverterRuns in Your Browser (No Uploads)

Generate TypeScript interfaces or type aliases from strict JSON examples. Object arrays are merged, fields missing from some items can become optional, unsafe property names are quoted, and everything runs locally in your browser.

What to do next

Continue with a related workflow or open the next tool that usually follows this task.

How to Use This Tool

Paste one strict JSON value or load the sample.

Enter a PascalCase root name such as ApiResponse.

Choose interface or type declarations and optional or readonly property behavior.

Generate the TypeScript and review warnings, unions, empty arrays, nulls, and optional fields.

Copy or download the declarations, then compare them with the real API contract and add runtime validation.

When to Use This Tool

API integration

Create a first draft of request and response declarations while integrating a REST or GraphQL endpoint.

Test fixtures and mocks

Describe fixture and mock payloads consistently before adding them to tests or Storybook stories.

Configuration models

Turn a configuration example into a readable TypeScript shape for application code and review.

Payload shape review

Compare several array records to spot fields that are absent, nullable, or represented with conflicting value kinds.

Common Mistakes

Treating one sample as the complete API contract

One object cannot show whether a field is truly optional. Optional markers are inferred only when object samples in the same array omit that field; confirm the contract with API documentation or a schema.

Guessing a type for an empty array

An empty array contains no evidence about its element type, so the generator uses Array<unknown>. Replace unknown only after checking a real payload or authoritative schema.

Assuming every JSON number is exact

Every JSON number maps to TypeScript number, but long integers and high-precision decimals may not be represented exactly at runtime. Use strings for exact identifiers and decimal libraries where precision matters.

Using static types as runtime validation

Generated declarations describe the sample shape; they do not validate untrusted data at runtime. Add a schema validator or explicit checks at the network boundary.

Examples

API object with quoted property names

Keys that are not valid TypeScript identifiers are quoted, while nested objects receive deterministic declaration names.

Input
{
  "id": 42,
  "user-name": "Ada",
  "profile": {
    "display name": "Ada Lovelace"
  }
}
Output
export interface ApiResponse {
  id: number;
  "user-name": string;
  profile: ApiResponseProfile;
}

export interface ApiResponseProfile {
  "display name": string;
}

Array records with optional fields

Object samples in one array are merged. Fields absent from some items become optional when optional inference is enabled.

Input
{
  "users": [
    { "id": 1, "name": "Ada" },
    { "id": 2, "active": true }
  ]
}
Output
export interface Generated {
  users: Array<GeneratedUsersItem>;
}

export interface GeneratedUsersItem {
  id: number;
  name?: string;
  active?: boolean;
}

Inference rules and safety limits

The source must be strict JSON with one root value. Comments, trailing commas, duplicate keys, malformed escapes, and more than 64 nesting levels are rejected instead of silently repaired.

Object arrays are merged by property name. Missing properties can become optional, and values with different JSON kinds become TypeScript unions. Empty arrays use unknown because their element type cannot be proven.

Valid ASCII property identifiers are emitted directly. Other keys are serialized as quoted string properties, while nested declaration names are generated deterministically and disambiguated when names collide.

The tool limits input, output, nesting, and node count. JSON numbers map to number, with a warning when the source literal cannot be represented exactly by a browser number. Static output still requires runtime validation for untrusted data.

Frequently Asked Questions

When does the output use interface or type?

Objects use the selected declaration style. A scalar or array root must use a type alias because an interface can describe an object shape but cannot directly alias string, null, or an array.

How are arrays of objects inferred?

All object samples in the same array are merged. A property missing from at least one item receives ? when optional inference is enabled; conflicting value kinds become a union.

What happens to an empty array?

The generator uses Array<unknown> and shows a warning. An empty sample provides no trustworthy evidence for string, number, or an object shape.

How are unusual JSON property names handled?

Keys such as user-name, 123, spaces, line breaks, and non-ASCII names are emitted as quoted string properties. This keeps the generated TypeScript syntax valid without changing the original JSON key.

Do generated types validate API responses?

No. The declarations describe the example but do not check data at runtime. Validate external input with a schema library or boundary checks before treating it as the generated type.

Does my JSON stay in the browser?

Yes. Parsing and type generation run in the browser. Use a redacted representative sample anyway, especially when production payloads contain secrets or personal data.

How This Tool Was Verified

Maintained and tested by Reviewed

Method: For “Merge two user records into one response shape”, we entered the documented fixture in JSON to TypeScript Interface & Type Generator and followed “Validate the source as strict JSON” before “Generate from several representative records”. We compared the browser result with the stated output, then reviewed “Using production secrets as a convenient sample” and “Inferring optional fields from one object” as separate failure boundaries.

Expected result: The two sample records merged into one users item interface with required id and optional name and active fields, rather than treating the first object as the entire schema.

Open the tested workflow

Related workflow guides

Use these focused guides when you need a practical workflow before opening the tool.

Related Tools

Continue with another maintained workflow

Browse All Tools