JSON à TypeScript

Générez des interfaces TypeScript à partir de JSON avec prise en charge des objets imbriqués.

Générateur JSON à TypeScript en ligne gratuit

Arrêtez d’écrire à la main pour les réponses API. Collez JSON et obtenez des interfaces TypeScript avec des objets imbriqués divisés en types distincts et des formes d'éléments de tableau déduites automatiquement.

Nommez votre interface racine, copiez la sortie dans votre projet et utilisez-la avec fetch ou votre client HTTP pour une sécurité de type totale. Tout fonctionne côté client dans votre navigateur.

Frequently Asked Questions

What TypeScript types are generated?
Primitive JSON values map to string, number, boolean, and null. Arrays become Type[] with the element type inferred from the first item. Objects become interfaces with named properties. Nested objects generate separate interface definitions.
How are optional fields handled?
Properties present in the sample JSON are included as required fields. If you need optional fields, add them to your sample JSON with null values, or manually add ? to the generated interface properties.
Can I name the root interface?
Yes. Set a custom root interface name before generating. Nested interfaces are named automatically based on property names (e.g., Address for an address object).
Does this handle union types?
The generator infers types from a single sample. If a field can be string or number, provide samples that include both variants, or manually adjust the generated type to a union (string | number).
Is the output compatible with strict TypeScript?
Yes. Generated interfaces use standard TypeScript syntax compatible with strict mode. Review nullable fields - JSON null maps to null in the type, not undefined. Adjust to field?: Type | null if needed.