Skip to content

JSON

JSON to TypeScript

Generate TypeScript types from JSON samples, including nested objects, arrays, unions and optional properties.

Loading tool…

Find this tool in

About this tool

What is JSON to TypeScript?

Use a representative JSON response to draft the TypeScript types needed by a client. Include several records when optional fields or mixed item types occur; a single object only demonstrates one observed shape. The generated declaration describes the sample, while your API contract must decide which values are genuinely permitted in production.

A worked example

Recognize that null is an observed value, not a future contract

Example input

{"id":7,"active":true,"note":null}

Expected result

"id": number;
"active": boolean;
"note": null;

The generated properties reflect the values that were present. If note can also be a string, supply a representative sample containing that case or amend the declaration to match the documented contract. Numeric samples do not establish a minimum, maximum or integer constraint. Review property names and unions before placing the declaration in a shared library.

Common mistakes and limits

  • TypeScript declarations are erased at runtime. Validate untrusted API data separately when a runtime guarantee is required.
  • An empty array provides no evidence about its future items. Check the generated fallback instead of assuming it discovered the intended element type.

Features

What you can do

  • Nested object and array types
  • Union types for mixed values
  • Optional properties for heterogeneous object arrays
  • Safely quoted property names

Frequently asked questions

Questions about JSON to TypeScript

Are inferred types a complete API contract?

No. They describe the supplied sample. Empty arrays use unknown, date values remain strings, and properties absent from some sampled objects become optional.

Related tools