JSON ↔ TypeScript Interfaces
Convert JSON into TypeScript Interfaces – and back.
Input
Output
What is JSON ↔ TypeScript Interfaces?
JSON → TS drafts a TypeScript type from one JSON sample. TS → JSON creates placeholder values from a simple, flat interface; it does not recover the original data. The two directions serve different purposes. Generated declarations are a starting point for review, not a complete API contract or runtime validation of incoming data.
How to use JSON ↔ TypeScript Interfaces
Paste {"id":1,"name":"Mira","active":true,"tags":["reader"]} and choose JSON → TS. The result should be an interface named Root with id as number, name as string, active as boolean and tags as string[]. Copy that generated interface, with its line breaks, back into Input and choose TS → JSON. Expect {"id":0,"name":"","active":false,"tags":[]}: placeholders replace the original values.
When is JSON ↔ TypeScript Interfaces useful?
Use JSON → TS to start a model from a small API fixture. Only the first element of each non-empty array is inspected. For {"values":[1,"two"]} the generated values field is number[], even though the second item is a string. Review all samples and add unions or optional fields yourself. Empty arrays produce any[]; a date string remains string.
Example
The reverse direction expects one simple property per line inside a flat interface. It recognizes string, number, boolean, null and types ending in [] as placeholders. It does not parse TypeScript syntax with a compiler: nested declarations, unions, generics, optional or readonly properties and single-line interfaces can give incomplete or misleading output rather than a syntax error. Copy the generated flat example above to try the supported path.
Practical notes
Try {"id":} with JSON → TS for an invalid-JSON message. JSON keys are emitted directly as property names; keys such as display-name require manual quoting before the declaration is valid TypeScript. The tool does not compile the result or check other files. Conversion runs locally without executing the input or contacting an API. Consult the TypeScript type reference when refining the generated model.