JSON a TypeScript
Pega una respuesta o fixture JSON y genera interfaces de TypeScript para objetos y arreglos anidados como un punto de partida práctico.
TypeScript
How to generate TypeScript from JSON
Infer TypeScript interfaces or type aliases from a JSON sample so API responses and fixtures are easier to type.
How inference works
Objects become interfaces, arrays become arrays of inferred item types, primitive roots become type aliases, and nested object names are built from the root name plus the property path.
Arrays and mixed values
When array items have different shapes or primitive types, the output uses a union of the inferred item types. Empty arrays become unknown[] because there is no sample item to inspect.
Review before using
- Rename interfaces if the generated names are too literal.
- Mark fields optional manually when a sample omits some cases.
- Replace null-only fields with a richer union if real data can contain other values.
Typing notes
Generated types describe the sample you pasted. Add optional fields, stricter unions, or shared interfaces when your real API contract is broader than the sample.
Preguntas frecuentes
Does it know which fields are optional?
No. It only sees the provided sample, so every object property in that sample is generated as required.
What happens with invalid property names?
Properties that are not valid TypeScript identifiers are quoted, so keys like user-name remain usable.
Why did I get a type alias instead of an interface?
Primitive JSON roots such as a string, number, boolean, null, or array can be represented directly as a type alias.
Can it merge several response examples?
No. Paste a representative combined sample or adjust the generated types manually after comparing examples.
