Skip to main content
eyunzhu

JSON to TypeScript types

Infer TypeScript types from JSON samples, including nested objects, optional properties, arrays, unions and null.

Types are inferred from this sample. Missing object properties become optional; empty arrays use unknown[].

Updates as you type or change an option


    
Processed in this browser. Nothing is uploaded or saved.

About this tool

Use representative response samples to draft a type for your application, then review it against the actual API contract.

How to use

Paste a representative JSON sample and choose a type name. Copy the generated export or download a .ts file. Array samples are combined: properties missing from some objects become optional and different value types form unions.

Empty arrays use unknown[] and empty objects use { [key: string]: unknown }. A sample cannot describe values it does not contain, so review the type against your API contract. Duplicate keys are rejected. Limits: 2 MiB, 30,000 values and 80 nested levels.

Common questions

Can a sample describe every possible response?

No. Types reflect only the supplied values. Missing properties across array samples become optional, and empty arrays become unknown[]. Runtime validation is not generated.

Is a generated number type safe for a very large JSON ID?

The generator labels JSON numeric values as number; it does not change how JavaScript parses them. Integers beyond JavaScript’s safe range can lose precision in your application. Use a string-based API representation or a parser that preserves large numbers, and review the generated type accordingly.

Comments

0
to join the discussion.
No comments yet.
Reply thread

Follow the complete conversation chronologically; each reply identifies the specific message it answers.