About JSON to TypeScript
JSON to TypeScript reads a sample JSON object and emits a TypeScript interface describing it, named Root. Nested objects become inline object types rather than separate named interfaces, which keeps a small payload readable in a single declaration and makes the structural relationship between the fields obvious.
Array handling follows the first element, so an array of strings becomes a string array; an array whose elements contain objects gets an inline object type per element with its own nested shape. Values are mapped by their JavaScript type, and a null is declared as null rather than being collapsed into something else.
The limitation to plan for is that inference sees exactly one example. Nothing is marked optional, so a property that is absent from half your real responses will be typed as always present. A field that is a string in one response and a number in another comes out as whichever the sample showed. Union types, enums and generics are not inferred. Widen the generated interface by hand against a few real payloads before treating it as the contract.
How to use JSON to TypeScript
- 1 Paste a representative JSON object, ideally one with every field populated.
- 2 Generate the interface and rename Root to something meaningful for your project.
- 3 Mark optional properties with a question mark where the API can omit them.
- 4 Add union types by hand for fields whose type varies between responses.
Frequently asked questions
Why is nothing marked optional?
Because a single sample shows only what was present, not what can be missing. The generator cannot distinguish a required field from an incidental one, so optionality has to be added from your knowledge of the API.
How does it handle a field that is sometimes null?
The field is typed as null if the sample showed null. If it is normally populated but occasionally null, add null alongside the real type — a union — so the compiler forces your code to handle both cases.
Can it generate nested interfaces instead of inline types?
It emits inline object types, which are easier to read for a shallow payload and quickly become unwieldy for a deep one. For a deeply nested response, extracting the inner shapes into named interfaces of their own is usually worth the restructuring.
Does it distinguish integers from decimals?
No. TypeScript has a single number type, so every numeric value is typed as number regardless of whether it was whole in the sample. If a value must be integral, that rule has to be enforced at runtime rather than expressed in the type.
Free, online, and private
Free to use
JSON to TypeScript is completely free. There is no account to create, no login, and no hidden charge or usage limit.
Runs online in your browser
It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.
Your data stays private
All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.
How JSON to TypeScript behaves in detail
These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.
| Parameter | Value |
|---|---|
| Input | a JSON document, parsed before any type is inferred |
| Output shape | one `interface Root`, with nested objects inlined |
| Array typing | taken from the first element — `T[]`, or `unknown[]` when empty |
| Sample size | a single document — whatever the sample contains is what the types describe |
Compiled from the implementation of this tool and checked against it by itoolnet.
What JSON to TypeScript does not do
Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.
- Types come from one sample, which is the fundamental limitation. A field that happens to be null in your sample is typed `null`, and one that is a number there is typed `number` even if the same endpoint sends a string for other records.
- Nested objects are inlined into the one `interface Root` rather than emitted as separate named interfaces, so a deep payload produces a single very long declaration that you will probably want to split by hand.
- Array element types come only from the first element. A mixed array, or an empty one, is not described as a union of the possibilities — inspect the output rather than pasting it in verbatim.
Tested and documented by itoolnet, the team that builds and maintains this site.