Start a TypeScript definition from sample data
Paste a JSON value, set the root name, and choose an interface or type alias. Nested objects receive their own declarations. Object arrays are inspected together so a field missing from some elements can be marked optional.
Example: a User interface
Use {"id":1,"name":"Alice","active":true}, set the root name to User, select interface, enable export, and leave optional/readonly off:
export interface User {
"id": number;
"name": string;
"active": boolean;
}
A sample is not an API contract
The output describes values present in the sample, not every response an API may return. An empty array yields unknown[], and a field containing only null yields null. Add domain rules and missing variants yourself. Generated types provide no runtime validation of incoming JSON.
Edge cases and hard limits
jsonToTypescript() parses the sample, then walks it: objects become interfaces, arrays are inspected to derive a union of their element types via union(), and repeated shapes are deduplicated so ten array items with the same structure produce one interface rather than ten. cleanName() rewrites keys into valid identifiers and capitalize() names the generated types, while declare() accumulates the output so nested objects come out as their own declarations instead of unreadable inline literals.
Formats, sizes and other limits
The output describes one sample, so it is only as complete as the data you pasted: an optional field that happens to be present becomes required, an empty array becomes an unknown element type, and a field that is sometimes a number and sometimes a string will be typed as whichever appeared. Nullable handling is present but shallow — deep optionality needs hand editing. Nothing is inferred about runtime validation, so the types are compile-time only.
Privacy: processed in your browser
The sample JSON is parsed locally and turned into type declarations in the page. No schema, key name or value is sent anywhere.
Frequently asked questions
Why is every field marked as required?
Because the generator only sees the sample. A key that is present in your sample looks mandatory; delete the marker where the API can omit it.
What happens with an empty array?
There is no element to inspect, so the type is unknown. Paste an example element, or write the element type by hand.
Can it generate zod or JSON Schema instead?
Not in this version. The output is TypeScript interfaces and type aliases, which you can feed into a validator generator afterwards.