English

JSON to TypeScript — Generate Types from JSON

Infer TypeScript types from JSON samples, including nested objects and arrays

Runs in your browser · nothing is uploaded

Infers types from one sample. Properties are required, empty arrays become unknown[], and varied array items form unions. This does not generate runtime validation.

Result

How to use

  1. Paste a JSON sample from an API response or configuration file.
  2. Set a type name such as Root or ApiResponse.
  3. Copy the exported type alias into a TypeScript file.
  4. Review properties that may be missing or nullable in real responses.

Inference rules

Strings become string, numbers become number, booleans become boolean and null stays null. Every observed object property is required. Property names are quoted, so Korean, Chinese, emoji and punctuation remain valid keys. Arrays combine distinct inferred shapes into a union, while empty arrays become unknown[]. An empty object becomes Record<string, never>.

This is sample inference rather than schema discovery. One successful response cannot reveal every error response or optional field. The tool rejects duplicate keys instead of silently discarding an earlier value. Comments and trailing commas are invalid JSON. Type names must use ASCII letters, digits, underscores or dollar signs, cannot start with a digit, and cannot be reserved words. Input is limited to one million characters and inference to 64 nesting levels.

Examples

{"name":"민수","score":3,"tags":["中文","😀"]} produces string for name, number for score and Array for tags. [1,"two",null] produces Array<number | string | null>.

Privacy

Conversion happens in your browser without uploading or saving the input. The output is a starting point for development; compare it with the documented API contract before relying on it.

FAQ

Are different object shapes merged into optional properties?

No. Array elements with different shapes become a union of those shapes. Review the result against the actual API contract.

What type does an empty array get?

It becomes unknown[] because the sample gives no evidence about its elements. Narrow it manually when you know the expected type.

Does this validate data at runtime?

No. It generates a type alias, not a parser or validation function. Types disappear when TypeScript is compiled.

Missing a tool?