JSON 转 TypeScript
从 JSON 示例生成支持可选类型和联合类型的 TypeScript 接口。
输入
结果
使用方法
Generating TypeScript interfaces
Paste a JSON sample and press Convert to obtain interfaces. Union types are produced for mixed arrays.
- Paste a JSON sample.
- Press Convert.
- Copy the interfaces into your project.
常见问题
Are fields marked optional?
Fields missing from the sample are not inferred, so optionality is only added when a value is null.
How are arrays typed?
Homogeneous arrays use a single type, mixed arrays produce a union type and empty arrays produce unknown[].