JSON to TypeScript
Paste a sample JSON object or array to generate matching TypeScript interfaces. Nested objects become their own named interfaces.
How to use it
Paste a representative JSON sample and click Generate. Types are inferred from the single sample provided — if a field can be null in some responses and a string in others, the generated type reflects only what's present in your sample.
Generated interfaces describe one sample
The converter maps object properties to interfaces, arrays to element types, and JSON primitives to TypeScript types. This is a quick way to replace an untyped payload with an editable starting point, but inference cannot discover values absent from the sample. Review optional fields, nullable values, unions, discriminators, enums, and API error shapes before committing the result.
Static types do not validate runtime JSON
A TypeScript interface disappears when code is compiled. Assigning a response to that interface does not check the bytes received from a server, local storage, a message queue, or user input. Keep runtime validation at trust boundaries with the validation approach already used by your application. The generated interface improves editor feedback only after the data has been checked or otherwise trusted.
Arrays and uncertain values
A homogeneous sample array produces one element type, while observed mixed elements produce a union. An empty array becomes any[] because there is no evidence about its contents. A field that is always null also lacks enough information to infer its non-null type. Replace broad results with the intended contract, and add optional markers only when the property may be absent rather than merely null.
Property names and object shapes
JSON property names can contain spaces, punctuation, or leading digits that are awkward as TypeScript identifiers. Keep quoted property names when the wire key cannot be renamed. Nested objects receive generated names based on their path; rename them to stable domain terms when several endpoints share the same concept. Similar-looking samples do not prove that two API objects have identical evolution rules.
A safer conversion workflow
Start with a representative success payload, then inspect empty collections, optional fields, null values, error responses, and pagination metadata. Compare the result with API documentation or generate a JSON Schema when you need an explicit data contract. Validate future samples against that contract and update types through review rather than silently regenerating them. Keep generated names consistent with the vocabulary already used by the application. All conversion happens locally and pasted JSON is not uploaded.
Frequently Asked Questions
What if an array has mixed types?
The generated type is a union of every distinct element type observed, e.g. (string | number)[].
What if an array is empty?
There's nothing to infer from, so it's typed as any[] — you'll likely want to replace that manually.
Do generated interfaces validate API responses?
No. TypeScript types are erased at runtime, so untrusted JSON still needs explicit runtime validation.