JSON to TypeScript Online – Generate Interfaces from JSON

Generate exported TypeScript interfaces and type aliases from one valid JSON sample without uploading it.

Runs locally
Ready to generate

Paste one valid JSON value to infer its current shape.

117 chars

Object samples become exported interfaces; arrays and primitive roots use exported type aliases.

0 chars

JSON to TypeScript guide

How to generate TypeScript interfaces from JSON

Paste one valid JSON value into the generator above, choose a root type name, and create exported TypeScript declarations that describe the observed object, array, primitive, and null shapes. Generation runs locally in your browser, so copied API responses and fixture data are not sent to a code-generation service. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Nested TypeScript interface generation
  • Root arrays and primitive type aliases
  • Homogeneous and mixed array type inference
  • Stable nested type naming
  • Quoted invalid TypeScript property names
  • Empty object and array fallback types
  • Invalid JSON line and column reporting
  • Browser-local processing

Steps

  1. Paste one valid JSON value into the sample input panel.
  2. Choose a clear root type name such as ApiResponse or UserPayload.
  3. Select Generate TypeScript and review nested interface names and mixed array unions.
  4. Copy the generated declarations, then refine optional fields and application-specific types in your project.

Objects become interfaces and arrays preserve observed item types

Non-empty objects become exported interfaces. Nested objects receive deterministic names derived from the root type and property path, while property names that are not valid TypeScript identifiers remain safely quoted.

Homogeneous arrays use one item type. Mixed arrays use a union, empty arrays use unknown[], and arrays of objects generate reusable item interfaces instead of inline anonymous object literals.

The first release describes one observed sample

A single JSON document cannot prove whether a field is optional, whether a string represents a date, or whether multiple response variants exist. This release intentionally describes the value that was pasted instead of inventing those business rules.

  • Every observed object property is required in the generated interface.
  • JSON numbers map to TypeScript number, and JSON null remains null.
  • Empty objects use Record<string, unknown> and empty arrays use unknown[].
  • Mixed item shapes remain explicit union types for human review.

Review generated types before using them as an API contract

Generated declarations are a development starting point, not proof of every production response shape. Compare representative payloads, mark genuinely optional fields, and replace broad or sample-specific types where your application has stronger knowledge.

The input is parsed and converted in the browser. VetaTool does not upload the sample JSON or generated TypeScript.

JSON to TypeScript example

A nested profile becomes its own interface, a string array becomes string[], and a property containing a hyphen remains quoted.

Sample JSON

{
  "id": 1,
  "profile": {
    "display-name": "Ada"
  },
  "roles": ["admin", "editor"]
}

Generated TypeScript

export interface ApiResponse {
  id: number;
  profile: ApiResponseProfile;
  roles: string[];
}

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

Common questions

Frequently asked questions

Does JSON to TypeScript upload my sample?

No. JSON parsing, type inference, naming, and code generation run locally in your browser.

Are generated properties optional?

Not in this first release. Every property observed in the single sample is emitted as required because one document cannot prove optionality.

How are mixed arrays represented?

Distinct observed item types become a TypeScript union. Different object shapes receive stable numbered item interface names for review.

What happens to empty objects and arrays?

Empty objects become Record<string, unknown>, while empty arrays become unknown[] because the sample provides no item evidence.

Does the generator detect dates or convert strings to enums?

No. Strings remain strings in this release. Date recognition, optional-field inference, and richer multi-sample merging are separate reviewable features.

Debugging a specific JSON issue? Browse JSON troubleshooting.