Tools

JSON to TypeScript interfaces

Paste an API response and get TypeScript interfaces or type aliases for it, with optional keys worked out from the data.

Runs in your browserCode converters13.9K
Free

Input

0 B

Result

The result will appear here.

Typing an API response by hand is slow, and it is where the mistakes creep in: a field that is sometimes missing, a value that is sometimes null, an array whose objects do not all share the same keys. This tool hands your JSON to quicktype, the type generator Glide open-sourced and the engine behind the Paste JSON as Code editor extension, and returns interfaces you can paste straight into a project. When the JSON is an array, every element is compared, so a key present in only some of them comes back optional and a value that is sometimes null comes back as a union with null.

How it works

  • quicktype-core runs in the page; the library is about a megabyte, so it downloads only the first time you press Run on this tool.
  • Nested objects become their own named interfaces, and identical shapes found in different places are merged into one type.
  • Strings that look like dates stay typed as string, because that is what JSON.parse actually gives you back.
  • Choose interface or type-alias declarations, mark every field readonly, and set the name of the top-level type.

Where your data goes

Nowhere. This tool runs entirely in your browser: the text you paste is processed by the page and is never transmitted to a server or written to a log.

This tool is free and needs no account. Its results exist only in your open page and are not saved anywhere.

What it costs

This tool is free, with no sign-in and no points.

Common questions

How does it decide a field is optional?
Only from the data you give it. If the JSON is an array of objects and a key is missing from at least one of them, that key gets a question mark. A single object carries no evidence either way, so every key in it is required. Paste several real responses as one array when you want the optional keys to be right.
Why is a field typed as null instead of string | null?
Because every sample value was null, quicktype had nothing else to go on — it cannot know what the field holds when it is set. mirror_url in the GitHub sample shows the case. Add an example where the field has a value, or widen the type by hand.
Interface or type alias — which should I pick?
For plain object shapes they are interchangeable in practice. Interfaces can be extended and merged by redeclaration, which some libraries rely on; type aliases can also express unions and mapped types. Most codebases standardise on one, so the option is there to match yours.
Does this validate the response at runtime?
No. TypeScript types disappear when the code is compiled, so a response that does not match still gets through. If you need the check at runtime, generate a Zod schema from the same JSON with the JSON to Zod tool on this site and parse the response with it.

The open-source behind it

This tool runs on glideapps/quicktype, released under Apache-2.0. If you need the same behaviour inside your own program, that is the library to reach for.

glideapps/quicktype

Also known as

  • json to typescript
  • json to ts interface
  • json to typescript type
  • generate typescript types from json
  • quicktype online
  • api response to typescript