JSON to TypeScript
Runs in your browserGenerate TypeScript interfaces from a JSON sample, with nested objects turned into their own named types. Runs in your browser.
About this tool
Typing an API response by hand is tedious and error-prone, especially when it nests several levels deep. Feeding in one real response gets you most of the way in a second. Treat the output as a first draft rather than a contract: inference can only describe the sample it was given, so a field that happens to be null in your example, or an array that happens to be empty, cannot reveal its real type — and nothing in a single sample distinguishes an optional field from a required one.
How to use
- Paste a representative JSON response — ideally one with all optional fields populated.
- Name the root interface.
- Copy the generated interfaces and adjust optionality and nullability by hand.
When to use this tool
- Typing a third-party API response you have no schema for.
- Bootstrapping DTOs from a sample payload.
- Turning a fixture file into types for a test.
- Documenting the shape of a legacy endpoint.
Tips
- Pick a sample where every optional field is present, otherwise those fields will be missing from the output entirely.
- Mark fields optional with ? yourself — a single sample cannot tell the generator which are.
- If a field can be null as well as a value, widen it to `string | null` manually.
Limitations
- Types are inferred from a single sample. A field that is null or an empty array in your example cannot reveal its real type, and optional fields look required.
FAQ
- Is my JSON uploaded?
- No. Parsing and inference happen in your browser. Nothing is transmitted or stored.
- Why is a field typed `null` instead of `string | null`?
- Because in the sample provided it was only ever null, and there is nothing else to infer from. Widen it by hand, or paste a sample where the field carries a value.
- Why is everything required?
- One example cannot distinguish 'always present' from 'present this time'. Adding ? where appropriate is the manual step this tool deliberately leaves to you.