Language
English

JSON to TypeScript

Infer TypeScript type definitions from JSON

Auto Detect
JSON Input
Paste a JSON object or array here...
TypeScript Output
Generated TypeScript will appear here...

togotools.top technical reference

Technical reference

Infer TypeScript interfaces or type aliases from JSON examples, including nested objects, arrays, unions, and optional fields. The input stays in the browser and the result is a practical starting point for API types.

Inference rules

  • Strings, numbers, booleans, and null map to TypeScript primitive types.
  • Objects become separate interfaces or type aliases, and arrays are inspected for element structure.
  • Merging samples can mark fields missing from some objects as optional.
  • Root names, exports, readonly properties, and semicolon style are configurable.

Example: API response to interface

json -> typescript
{"id":1,"name":"Ada","tags":["admin"]}

export interface Root {
  id: number;
  name: string;
  tags: string[];
}

Limits of inference

JSON is a runtime sample and cannot express business constraints, dates, currency, ID formats, or dynamic server-side unions. Treat the result as a type draft and refine it against the API contract.

  • An empty array does not provide enough information to infer its element type.
  • Inconsistent field types across samples may produce a union that needs review.
  • Generated TypeScript does not validate future responses; use a runtime schema when needed.

Frequently asked questions

Can this tool generate a runtime validator?

No. It generates compile-time TypeScript types. Use a schema library such as Zod or Ajv when runtime validation is required.

Why is an array type sometimes too broad?

Inference only sees the supplied sample. Empty or incomplete arrays cannot reveal the full element structure.