JSON -> TYPES · Local tool
JSON to TypeScript
Turn a JSON sample into TypeScript interfaces or a JSON Schema.
Last updated
How do I generate TypeScript types from a JSON response?
Paste a sample response into filetity and TypeScript interfaces appear beside it, or a JSON Schema draft 2020-12 document from the same inferred shape, so the two can never disagree about what is required. Nothing is uploaded, which matters because the useful sample is usually a real API response with real records in it. Two decisions make the output worth using. Every element of an array is folded into one shape, so a list where some records carry an extra field gives one interface with that field optional rather than a union of near-identical shapes you would have to narrow between. And an absent key and a null value are kept apart: a question mark means the key was missing from some records, while null means it was present and held null, and neither is turned into the other.
01 / Your device
the file stays here
02 / Browser memory
the work runs locally
03 / Back to you
saved on this device
When you would use this
Situations, not settings.
- An API with no types and no documentation
- Paste one real response and get interfaces you can paste into the project, rather than typing them out from what you can see in a network tab.
- Validating a payload you do not control
- The JSON Schema comes from the same inferred shape as the interfaces, so the runtime check and the compile time types agree by construction.
- A list where some records have extra fields
- Every element is folded into one interface with the one-sided keys optional, which is what a list of records actually is.
How it works / no cloud
A conversion engine, not an upload form.
The sample is parsed and every element of an array is folded into one shape, so a list of records where some entries carry an extra field produces one interface with that field optional, rather than a union of near-identical anonymous shapes. The TypeScript and the JSON Schema come from that same inferred shape, so they cannot disagree about what is required.
- Offline ready
- Installable app
- No file limit queue
Straight answers
No accordion. Nothing hidden.
- Is it free?
- Yes, with no watermark and no page limit.
- Does it need an account?
- No. There is no account system.
- Is my file processed on my device?
- Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- What formats are supported?
- Any valid JSON in. TypeScript interfaces out, or a JSON Schema draft 2020-12 document.
- What are the limits?
- It can only describe what your sample contains. A field that is always null in the sample is typed null, because that is the one thing the sample actually said.
- Does it work on mobile?
- Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Does it work offline?
- Yes, once the page has loaded. The tool keeps working with no network connection.
- What is the difference between a? and | null in the output?
- A question mark means the key was missing from some records in your sample. Writing null means the key was there and held null. They are different claims about your data and neither is silently turned into the other, because only one of them is something the sample demonstrated.
- Why is my array of records one interface instead of a union?
- Because that is what a list of records is. If one entry has a nickname and the others do not, the useful answer is a single interface with an optional nickname, not a union of two shapes you then have to narrow between on every access. Every element is folded into one shape and one-sided keys become optional.
- What do I get for an empty array?
- It becomes unknown, not any. An empty array carries no information about what belongs in it, and typing it any would quietly switch the type checker off for everything downstream of it, which is the opposite of why you generated types.
- Are numbers ever typed as integers?
- Not in the JSON Schema, no. A sample containing only whole numbers does not prove the field is an integer, and guessing produces a schema that rejects valid data the first time somebody sends a decimal. Every number is typed as a number, which is what the sample supports.
- Do nested objects get their own interfaces?
- Yes, named after the key they sit under, so an address inside a user becomes an Address interface. Inlining everything produces a two hundred line type nobody can read or reuse, and a name that collides with one already used gets its parent's name in front of it.
Keep working locally
3 available · more coming