Binatomy
TypeScript 生成器

JSON 转 TypeScript

Paste JSON and instantly generate TypeScript interfaces, with recursive inference of nested objects, arrays and optional types
常见问题

常见问题

Everything you need to know about generating TypeScript interfaces

如何从 JSON 推断类型?

The tool recursively analyzes your JSON: strings become string, numbers become number, booleans become boolean. Each nested object generates its own interface with a PascalCase name derived from the key, while arrays produce [] types by inferring the element type. Null values are treated as optional properties.

如何处理数组和混合类型?

For arrays, the tool examines all elements and builds a union type when it finds different types (for example (string | number)[]). An empty array becomes any[]. If the elements are objects, a reusable interface with a singular name is generated. All computation happens in your browser, your JSON never leaves your device.

JSON 里的 null 会怎么处理?

源 JSON 里的 null 会生成一个用问号标记为可选、类型为 null 的属性,因为只凭一个样例无法推断这个字段真正的类型。