JSON 转 TypeScript
UpBox优盒工具箱,免费在线 JSON 转 TypeScript 工具,自动推断字段类型与嵌套结构,生成 interface 或 type 定义,支持数组与可选字段。
无需注册 · 数据不上传No sign-up · nothing uploaded
源 JSONSource JSON
TypeScript 定义TypeScript definitions
粘贴 JSON 后自动生成
数组会按元素结构合并字段,缺失字段自动标记为可选
本工具所有运算在本地浏览器完成,你的文件、文本不会上传到服务器
工具介绍
把接口返回的 JSON 直接粘贴进来,工具会逐层推断字段类型,嵌套对象拆成独立 interface,数组按元素结构合并,缺失字段自动标记为可选。 Paste a JSON response and the tool infers each field type: nested objects become their own interfaces, arrays merge item shapes, and missing fields turn optional.
可以自定义根类型名、在 interface 与 type 之间切换,也可以把所有字段设为可选或只读,输出可直接粘进 .ts 文件。 Set the root type name, switch between interface and type, or mark every field optional or readonly — the output pastes straight into a .ts file.
- 类型自动推断Automatic type inference
- 嵌套对象拆分Nested object extraction
- 数组结构合并Array shape merging
- 可选与只读Optional and readonly
- 本地处理Local processing
使用说明
- 粘贴 JSON,自动生成定义。Paste JSON to generate definitions.
- 按需修改根类型名与输出风格。Adjust the root type name and output style.
- 勾选“所有字段可选”或“只读字段”。Toggle optional or readonly fields.
- 复制代码或下载 .ts 文件。Copy the code or download a .ts file.
常见问题
数组元素结构不一致会怎样?What if array items differ?
工具会合并所有出现过的字段,缺失字段标记为可选,类型按首个元素推断。Fields from all items are merged, missing ones become optional, and types follow the first item.
null 值怎么处理?How is null handled?
纯 null 输出 null;与其它类型混合时按元素顺序取首个类型,建议生成后手工调整联合类型。A null-only value maps to null; mixed arrays follow the first item — refine unions by hand if needed.
支持生成 zod schema 吗?Does it generate zod schemas?
暂不支持,当前只输出 TypeScript 的 interface 与 type。Not yet — only TypeScript interfaces and type aliases.
数据会上传吗?Is data uploaded?
不会,解析与生成都在浏览器本地完成。No, parsing and generation run locally.