TS

JSON 转 TypeScript

从 JSON 生成 TypeScript 接口

🔒 100% client-side — your data never leaves this page
JSON Input
TypeScript Output
TypeScript types will appear here

About this tool

粘贴任意 JSON 对象,即时生成 TypeScript interface 或 type 类型定义。支持嵌套对象递归生成、数组、基础类型和 null 值处理。可切换 interface/type 关键字,适合快速为 API 响应数据添加类型定义。

Frequently Asked Questions

What is the difference between interface and type in TypeScript?

Both can describe object shapes, but interfaces are extendable and mergeable while types are more flexible and can represent unions and intersections. For plain object shapes from JSON, both work equally well.

Does it handle nested objects?

Yes. Nested objects are recursively converted into separate named interfaces, keeping your type definitions clean and reusable.

What happens with null values?

null values are typed as null. In practice you may want to change these to T | null or use optional fields depending on your API contract.