JSON to TypeScript
Generate TypeScript interfaces from sample JSON objects or arrays.
Generate TypeScript from JSON
This JSON to TypeScript converter generates TypeScript interfaces from JSON objects or arrays. Nested objects become their own interfaces, and arrays become array types. Converting a JSON array to TypeScript uses every object in the sample. Set the root type name, then copy or download the .ts file. Conversion runs in the browser.
A property is optional only when some objects in a top-level array leave that key out. Null stays null, and a field that is sometimes null becomes a union. An empty array has no items to inspect, so its element type is null until you add a sample item. Dates remain strings because JSON does not record a date type. If you need runtime validation, generate a schema with the JSON to Zod tool.
Common questions
How are optional properties inferred?
Optional properties appear only when the pasted JSON is a top-level array of objects and some objects omit a key. A single object treats every key it contains as required. When an array nested inside an object contains objects with different keys, each shape becomes its own interface and the property is a union of those interfaces inside an array type, such as (First | Second)[].
How are null values handled?
A null is typed as null. If the same field is a value in some objects and null in others, the generated type is a union that includes null.
Can JSON dates automatically become Date types?
No. JSON has no date type, so a date written as text stays a string. Change that to Date in your project if you need to.
Related tools
- JSON
JSON Minifier
Remove whitespace from JSON without changing its structure.
Coming soon