← All JSON guides

JSON guide · 7 min read

How to Generate TypeScript Interfaces from JSON

Generate TypeScript types from sample JSON and review optional fields, unions, nullability and nested object names.

Published 2026-08-05Reviewed 2026-08-05

What a generator can infer

A sample reveals observed property names, primitive types, arrays and nested objects. A generator can quickly create readable interfaces for that shape.

One sample hides optionality

A field present in one payload may be absent in another. Review API documentation and multiple samples before deciding whether to add the optional marker.

Review arrays, nulls and mixed values

Empty arrays do not reveal their element type, null does not reveal the non-null type and mixed arrays may need unions or a redesigned model.

  • Name reusable nested types clearly.
  • Use unknown instead of any when appropriate.
  • Model nullable and optional fields separately.
  • Validate runtime data because TypeScript types disappear at runtime.

Common questions

Frequently asked questions

Do TypeScript interfaces validate JSON at runtime?

No. They provide compile-time checking only; runtime data still needs validation.

Why did the generator choose any or unknown?

The sample may not contain enough information, especially for empty arrays, null values or inconsistent records.