JSON → TypeScript type inference
Infer parseable TypeScript interfaces/types from a JSON sample: nested objects, arrays, null, empty objects, mixed-array unions and quoted special keys; computed locally.
Inputs and parameters
input— JSON inputrootName— Root type nameoutputStyle— Declaration styleexportDeclaration— Add the export keyword
Real example
{"id":1,"active":true,"deleted":null,"empty":{},"tags":["a",2,{"x":false}],"__proto__":{"polluted":true}}
→ // 空对象推导为 Record<string, never>;它表示「没有已知键」,不是任意对象。
export interface RootTagsItem {
x: boolean;
}
export interface Root__proto__ {
polluted: boolean;
}
export interface Root {
id: number;
active: boolean;
deleted: null;
empty: Record<string, never>;
tags: Array<string | number | RootTagsItem>;
"__proto__": Root__proto__;
}
Limits and failure handling
One JSON sample can only describe shapes present in that sample, not every runtime value. Large integers are typed number with an explicit precision warning. This is not a full configurable type system. Input is capped at 1 MiB / depth 64 / 60000 nodes; errors include line and column.
FAQ
How are empty arrays and objects handled?
An empty array has no sample element and becomes unknown[]; an empty object becomes Record<string, never>. Neither invents structure.
What about hyphenated or reserved field names?
Property names are quoted automatically, e.g. "a-b", "constructor" and "__proto__", so the declaration remains parseable TypeScript.
Can it evaluate JavaScript object literals?
No. Unquoted keys, single quotes, comments and functions are rejected; input must be strict JSON and user code is never evaluated.