Convert JSON to TypeScript
Turn a sample response into interfaces.
About this converter
Paste a real response and get interfaces for it, which is quicker and more accurate than writing them from the documentation — assuming there is documentation.
Paste several records, not one. This is the thing that makes the result usable: given a list, a field present in some records and missing from others is marked optional, which a single sample can never tell you. One object produces a type that claims every field is always there, and that is a type that lies.
A null becomes part of the type rather than the whole of it, because a null in a sample says the field can be null. A field that is a number in one record and a string in another widens to a union rather than quietly picking the first — that disagreement is real, and hiding it is how a parser breaks in production.
Frequently asked questions
Why should I paste more than one record?
Because optional fields are invisible in a single sample. Given a list, a key that appears in four records out of six is marked with a ?; given one record, every key looks mandatory. The more of the real response you paste, the closer the type is to the truth.
What happens to a field that is null in my sample?
It becomes part of the type — string | null rather than just null. A null tells you the field is nullable, not that it is always empty. If a field is null in every record you pasted, the type is exactly null, which is a signal to paste a record where it has a value.
Why is one of my types "unknown"?
Because the same field held genuinely different shapes — an object in one record and a string in another. There is no type that is both, so rather than pick one and be wrong half the time it says so, and you can decide what the field really is.
Are these types validated at runtime?
No, and it is worth being clear about it. TypeScript types vanish at compile time, so they describe what you expect rather than check what arrived. If the response can differ from the type, you want a runtime validator such as Zod or Valibot as well — the interface here is a good starting point for writing one.
Does what I paste get sent anywhere?
No. Everything runs in your browser, on your own machine. Nothing is uploaded and nothing is logged. That matters more here than on most pages — source code, database queries and internal data are exactly the things that get pasted into tools like this, and most of them are a form that posts to a server.