JSON to TypeScript converter
Infer TypeScript declarations from a JSON sample, including unions, optional properties and nested objects. Review the generated code before adopting it as an API contract.
Infer TypeScript declarations from a JSON sample, including unions, optional properties and nested objects. Review the generated code before adopting it as an API contract.
Maximum 200 KiB UTF-8; nesting limit: 50 levels.
For an array or primitive root, interface mode emits a root type alias.
Types describe only the sample. Missing properties become optional; null remains explicit; empty arrays use unknown[]. This does not validate data at runtime.
Paste valid JSON or load the synthetic example. Include representative variants of the structure you want to describe.
Enter a valid root name, such as ApiResponse, and choose interface or type. Non-object roots use a type alias.
Select Convert, review optional properties and unions, then copy or download the .ts file. Check it with your compiler.
The second record has active but the first does not, so active is optional. Both observed tag types appear in the union.
[{"id":1,"tag":"x"},{"id":2,"tag":null,"active":true}]export type ApiResponse = ({
active?: boolean;
id: number;
tag: null | string;
})[];Null remains an explicit type and may appear in a union. An empty array becomes unknown[] because there are no elements to infer from.
No. TypeScript checks types during development; these declarations do not inspect future API responses. Add a runtime validator when needed.
Infer TypeScript declarations from a JSON sample, including unions, optional properties and nested objects. Review the generated code before adopting it as an API contract.
The second record has active but the first does not, so active is optional. Both observed tag types appear in the union.
Maximum 200 KiB UTF-8; nesting limit: 50 levels. Processed in this browser. No data is uploaded or saved.
Both describe objects. Type emits an alias; interface emits an interface for an object root. An array or primitive root requires an alias even in interface mode.
All objects in the same array are compared. A property missing from any object is marked with ?. A null value is different from an absent property.
Null remains an explicit type and may appear in a union. An empty array becomes unknown[] because there are no elements to infer from.
No. TypeScript checks types during development; these declarations do not inspect future API responses. Add a runtime validator when needed.
The result only knows the values provided. It does not discover future fields, business rules, dates or enums. Use varied samples and review the actual contract.