Convert a JSON sample into readable TypeScript interfaces and types directly in your browser. Nested objects, arrays, unions, and unusual JSON keys are supported.
What is JSON to TypeScript?
JSON to TypeScript generation inspects one JSON example and describes its observed shape using TypeScript interfaces and types. It helps create a starting point for API response types without manually transcribing every field.
How to Convert JSON to TypeScript
Paste valid JSON, choose a root type name, and select Generate. The output is plain TypeScript text that you can copy or download as a .ts file. Input is parsed only after you generate.
Supported JSON Types
Strings, numbers, booleans, null, objects, and arrays are supported. Arrays of different primitive values produce union element types. Empty arrays use unknown[] because a sample with no elements does not reveal the element type.
Arrays and Nested Objects
Nested objects become named interfaces. Arrays of objects use interfaces inferred from their observed entries; differing object shapes become unions. Repeated compatible shapes reuse an existing generated interface.
Limitations of Sample-Based Type Generation
Generated types describe only the supplied sample. A property that appears in the sample is marked required, but the sample cannot prove every future response contains it. This tool does not infer API guarantees, validate a schema, or compile or execute the generated TypeScript.
JSON to TypeScript Features
- Generate a named root interface or type
- Infer nested interfaces and array element types
- Represent mixed values as deduplicated unions
- Quote property names that are not valid identifiers
- Copy or download generated TypeScript locally
Frequently Asked Questions
Is my JSON uploaded?
No. Conversion runs in your browser. The JSON input is not sent to ToolCoda servers or an external API.
How are empty arrays typed?
An empty array is generated as unknown[] because there are no sample elements from which to infer a narrower type.
Are generated properties optional?
No. Properties found in the sample are required in the generated type. Use additional samples or edit the output if your real data can omit a property.
Does this tool compile the generated TypeScript?
No. It generates TypeScript source as text and never executes or compiles it in the browser.