My Tool Studio
Developer

JSON to TypeScript

You fetch an API response, and now every property access on it is an any. Paste a real sample into this json to typescript generator, give the root interface a name, and press Generate types: each field is inferred, nested objects become nested type literals, and mixed arrays come back as union types. It's the quickest json to ts step between the endpoint working and the compiler checking your usage. Keys that aren't valid identifiers get quoted automatically, so the generated json to typescript interface compiles as pasted. The sample never leaves your browser, which matters when it's production data.

Always freeNo sign upRuns in your browser
Output appears here...

How to use

01

Paste a representative sample

Use a real API response if you can, since types are inferred from exactly what you paste. Try sample loads a small object with nesting to demonstrate.

02

Name the root and generate

Type a name into the Root name field, then press Generate types. The output is one exported interface describing the entire structure, nested parts included.

03

Paste into your project

Copy the interface into a .ts file and start typing your fetch calls with it. When the API shape changes, paste a new sample and regenerate.

Why JSON to TypeScript

Common questions

How are arrays with mixed element types handled?
They become union types. An array holding both strings and numbers is typed as a combined string or number array rather than falling back to any, so the output stays honest about what the data contains. Uniform arrays get the simpler single-type form.
What does a quoted key in the generated interface mean?
It means the original JSON key isn't a valid TypeScript identifier, things like content-type or keys starting with a digit. Quoting keeps the interface compiling without renaming your data. Access those properties with bracket notation in your code.
Does it also produce a JSON Schema?
No, the output is TypeScript only. A json schema converter or json to schema converter describes runtime validation rules, which is a different artifact from compile-time types. If you need both, generate the types here and use a schema library for the runtime side.
Does this generate types from JavaScript source code?
No. Searches for a js to ts converter online or a way to convert javascript to typescript online are about migrating code files, which involves rewriting syntax and annotations. This page does something narrower: it reads a JSON data sample and writes the types that describe it.
Why are all the generated fields required?
Because one sample can't reveal which fields are sometimes absent. The generator types exactly what it sees, so if your API omits fields in some responses, add ? markers to those properties yourself, or paste a sample from each variant and merge the results.
Is escaped JSON, a string inside a string, accepted?
Not directly; it'll parse as one big string and produce a useless type. Unescape it first with the JSON Formatter, which handles json string to json cleanup and works as a json formatter online free of charge, then paste the clean object here for real types.
Will null values in my sample produce usable types?
A field that's null in the sample is typed as null, which is accurate but rarely what you want long term. Replace it with the field's real type union once you know it, or grab a sample where the field is populated before generating.

More Developer tools

View all