簡單物件
輸入
{"id":1,"name":"Ada","active":true}輸出
export interface Root { id: number; name: string; active: boolean; }AppHelp
貼上一個 JSON 物件或一組樣本,即時取得可編輯的 TypeScript 定義,並可推斷選用欄位、調整命名、複製或下載 .ts。
貼上 JSON 樣本後立即取得可編輯的 TypeScript 定義。
export type Root = RootItem[];
export interface RootItem {
id: number;
name: string;
roles: string[];
nickname?: string;
}型別依樣本值推斷。用於正式環境前請核對選用欄位、null 與空陣列的真實契約。
貼上有效 JSON 即可即時產生 TypeScript interface 或 type。巢狀物件會產生具名宣告,陣列中的多個樣本會合併,缺少欄位可標記為選用,混合值會形成聯集型別,null 也會明確保留;所有處理都在瀏覽器本機完成。
{"id":1,"name":"Ada","active":true}export interface Root { id: number; name: string; active: boolean; }[{"id":1},{"id":2,"nickname":"lin"}]export interface Root { id: number; nickname?: string; }啟用缺少鍵推斷後,只在部分樣本中出現的屬性會帶 ?。
[{"score":9.5},{"score":null}]score: number | null;
null 會被保留,而不是靜默轉成 any。