JSON to TypeScript Converter
JSON to TypeScript Converter generate typescript interface from json json sample to ts type convert api json to typescript privateCreate a starting interface from sample data
Paste valid JSON, choose a legal TypeScript root name, and select Generate TypeScript. The result infers primitives, nested object shapes, array members, and null values from the supplied sample.
Inference describes the sample, not the API
A JSON response can demonstrate values that happened to arrive once. It cannot reveal every optional field, permitted enum, numeric range, date format, or alternate response shape. Generated TypeScript is therefore a useful draft for review, not an authoritative contract.
Worked example
Paste {"id":7,"name":"Maple","active":true,"tags":["new","sale"]}. The output gives id a number type, name a string type, active a boolean type, and tags a string-array type. An empty array becomes unknown[] because no member exists from which to infer a narrower type.
Mixed arrays and nulls need judgment
When an array sample contains several kinds of values, the generator returns a union of observed member types. A field containing null becomes null, even if real responses sometimes contain a string. Expand such fields manually into appropriate unions. Decide which properties should be optional only after inspecting multiple responses or the API schema.
Types do not validate runtime input
TypeScript checks code during development; it does not automatically reject an invalid server response at runtime. Use a runtime schema library or explicit validation when data crosses a trust boundary. Dates remain strings because JSON has no date type. Integers and decimals both become numbers, subject to JavaScript precision limits.
Privacy and limitations
Conversion stays in this tab. The tool does not upload API samples, follow references, read JSON Schema or OpenAPI, generate classes, choose domain names for nested shapes, or merge several documents. Nested object types remain inline so output is honest and easy to inspect.
JSON to TypeScript FAQ
Why are properties not optional?
A single sample cannot prove whether an observed property is optional.
Why is a date a string?
JSON represents dates as strings or numbers; application meaning needs separate knowledge.
Does this protect runtime code?
No. TypeScript types disappear at runtime unless you add validation.