JSON to TypeScript
Generate TypeScript interfaces from a JSON sample, with nested types and optional fields.
Missing a feature or found a bug in JSON to TypeScript? Tell me on X (@_andrewtran) or by email.
How to use JSON to TypeScript
- Paste a JSON sample in the input pane.
- Set the name of the root type if you want one other than Root.
- Copy the interfaces or download them as a .ts file.
Questions and answers
Is my data sent anywhere?
No. Everything runs in your browser on this device. Nothing you paste is uploaded or stored.
How are optional fields found?
When a list holds several objects, a key that is missing from some of them is marked optional with a question mark.
What about values that are null?
They are typed as null, because one sample cannot show what else the value may hold. Widen the type by hand where you know more.
Related tools
JSON Schema generator
Infer a JSON Schema from sample JSON, with types, required keys and item schemas.JSON flatten and unflatten
Flatten nested JSON to dot-path keys such as user.tags[0], or turn flat keys back into nested JSON.JSON escape and unescape
Turn text into a JSON string literal with quotes and line breaks escaped, or turn one back into text.HTML entity encoder
Escape text as HTML entities, or decode entities such as & and ' back into characters.