JSON → TypeScript
Turn a JSON sample into TypeScript interfaces, with nested shapes and unions resolved.
JSON
Paste a JSON sample
Types are generated as you type
TypeScript
Types appear here.
Processed locally in your browser. Type generation is pure client-side code. Your sample never leaves the browser.
Reference
How the shape is inferred
Every value in the sample is mapped to the narrowest TypeScript type that describes it, and nested objects become their own named declaration. Arrays are not sampled from the first element: every element is unified, so an array whose objects differ produces one type that covers all of them.
| JSON | TypeScript |
|---|---|
| "text" | string |
| 42, 1.5 | number — JSON has no integer type, so neither does the output |
| true | boolean |
| null | null, unioned with the type seen elsewhere for that key |
| [1, 2] | number[] |
| [1, "a"] | (string | number)[] |
| [] | unknown[] — an empty array carries no type information |
| { "a": 1 } | A named interface, reused wherever the same shape appears |
Optional keys
A key that is present in some array elements and missing from others is marked ?. This is inference from one sample, not a contract: if your API can omit a field that happens to be present everywhere in the sample, the generated type will be stricter than reality. Turn the option off if you would rather start from required fields and relax them by hand.
Naming
Nested types are named after the key that holds them, converted to PascalCase and singularised for arrays — items yields Item. Identical shapes share one declaration rather than being duplicated, and colliding names get a numeric suffix. Property names that are not valid identifiers are quoted.
What it will not do
There is no discriminated-union detection: a list of objects with a kind field is merged into a single shape with optional members rather than split into a union. Dates stay string, because JSON has no date type. Treat the output as a fast starting point you then edit, not as a schema.
Questions
- How are optional properties decided?
- By looking across an array of objects. If a key is present in some elements and missing in others, it is emitted as optional. From a single object every key is required, because one sample cannot tell you what is optional.
- What happens to null values?
- A null becomes null in the generated type, and a field that is sometimes null and sometimes a string becomes string | null. That is deliberate: widening it to any would hide exactly the case that causes runtime errors.
- Can it generate types for a whole API?
- It generates types from the sample you paste, so one response at a time. For a whole API where the server publishes an OpenAPI document, generating from that document is more reliable, because it describes fields your sample happened not to include.