JSON to TypeScript Interface
Generate TypeScript interfaces from a JSON sample. Infers types, nested shapes, and arrays. Output is ready to paste into your codebase.
How it works
Turning sample JSON into a TypeScript interface is one of the most common chores when integrating an API. You have a response example, you want compile-time safety, and manually transcribing twenty fields is error-prone. This tool walks the JSON tree once, inferring primitive types, extracting nested objects into their own interfaces, and unifying array element types.
Primitive inference is straightforward: numbers become `number`, strings become `string`, booleans become `boolean`, and `null` becomes `null`. Nested objects get promoted to named interfaces keyed by the parent property name — so a field called `profile` yields a `Profile` interface that the root references. Arrays unify their element types, so `[1, "x", 2]` becomes `(number | string)[]`.
A few caveats: the generator uses a single JSON sample, so optional fields are not detected. If a field can be absent, mark it with `?` manually. Very deep or recursive structures generate a long chain of interfaces; you may want to collapse some back into inline types for readability. Dates are treated as strings (ISO 8601), not `Date` objects — since JSON has no native date type, you must parse them yourself at the boundary.
Frequently asked questions
- Does this create nested interfaces for nested objects?
- Yes. Each nested object is extracted into its own interface named after the parent key (PascalCased).
- How are arrays with mixed types handled?
- The element type becomes a union, e.g. `(string | number)[]`. Empty arrays default to `unknown[]`.
- What about null values?
- A null value is typed as `null` and joined with the inferred non-null type as a union, e.g. `string | null`.
Related tools
- JSON to YAML ConverterConvert JSON to clean, human-readable YAML instantly. Runs fully in your browser — no upload, no tracking.
- YAML to JSON ConverterConvert YAML to JSON (pretty-printed, 2-space indent) in your browser. Handles anchors, multi-doc files, and nested structures.
- JSON to CSV ConverterConvert a JSON array of objects to CSV online. Auto-detects columns, escapes quotes, supports nested fields via dot notation.
- CSV to JSON ConverterConvert CSV to JSON online. Auto-detects delimiters, parses headers into object keys, and coerces numbers and booleans.