QCSunny Lab

JSON to TypeScript Interface GeneratorJSON 转 TypeScript 接口生成器

Output转换输出

Paste a JSON response and get clean TypeScript interfaces: nested objects become their own named interfaces, and object arrays merge into a single interface where keys missing from some items are marked optional.

Nulls map to null, empty arrays to unknown[], and mixed-type arrays become a union — matching what a real API returns rather than what a schema wishes it returned.

Frequently asked questions

Why are some fields optional?

A key that appears in some array items but not all is marked with ?. This is inference from evidence: the sample shows the key can be absent.

What about JSON Schema or OpenAPI?

Those describe intent; this tool describes the data you actually have. For API contracts, prefer generating from the schema; for poking at a live response, this is faster.

中文说明

粘贴一段 JSON 响应,即可得到干净的 TypeScript 接口定义:嵌套对象生成独立命名的 interface,对象数组自动合并为单一接口,部分元素缺失的键会标注为可选字段。

null 映射为 null、空数组映射为 unknown[]、混合类型数组生成联合类型——忠实反映 API 的真实返回,而不是 schema 的美好愿望。

常见问题

为什么有些字段是可选的?

数组中部分元素有、部分没有的键会标注 ?。这是基于证据的推断:样本证明了这个键可能缺失。

和 JSON Schema / OpenAPI 生成有什么区别?

Schema 描述"意图",本工具描述"实际拿到的数据"。定义 API 契约请用 schema 生成;临时看一个线上响应,这里更快。