⚡ Curated dev resources & dealsSponsored
DevToolBayFree Developer Tools

JSON 转 TypeScript

粘贴 JSON 样本即生成 interface:嵌套类型命名、可选字段标记、字面量并集,非法键引用式书写。

Root name

Inference rules

Every JSON object becomes an interface named after its key (PascalCased); arrays sample their elements and emit element-type unions or …[]; null becomes the null type; numeric keys or keys with symbols are emitted as quoted string keys. Structures deeper than 12 levels collapse to unknown. Reused interface names reference the first definition — the output is deterministic for the same input.

如何使用JSON 转 TypeScript

把有代表性的 JSON 样本——接口响应、配置或测试数据——粘进来,每个对象层级都得到一个 interface:嵌套类型自动命名、可选字段打标记、字面量值收敛成并集。严格性与 null 处理由选项决定。

对象数组的多个实例会合并成一个元素接口, heterogeneous 样本也能得到一个准确的类型。输出直接复制进项目,接口演化后用新样本重新生成即可。

相关工具