/tools/json-to-typescript

JSON to TypeScript Converter

Generate interfaces or type aliases with nested declarations, optional properties, unions, and explicit nulls.

json-to-typescript://local

JSON sample

TypeScript output

Ready. Paste valid JSON or choose a file to infer TypeScript types locally.

/usage

How to convert JSON to TypeScript

  1. Paste representative JSON, drop a file, or load the sample response.
  2. Choose interfaces or type aliases, exports, optional markers, and readonly properties.
  3. Generate, review the inferred contract, then copy or download the .ts file.

/inference

Useful TypeScript from real API samples

All array objects contribute

The converter merges every object sample in an array. Properties missing from some samples can become optional, while observed null values remain explicit null unions.

Mixed values remain unions

Unlike a first-item-only generator, differing string, number, boolean, object, array, and null evidence is retained as a TypeScript union instead of silently discarded.

Safe property and type names

Nested type names are deterministic and collision-safe. Property keys that are not valid TypeScript identifiers are quoted so their original JSON spelling remains exact.

Compact, bounded inference

One shared inference core records types and field occurrence counts rather than retaining duplicate values. Work runs off the main thread and is bounded by input, traversal, depth, schema, and output limits.

/faq

JSON to TypeScript questions

Is my API response uploaded?

No. JSON parsing, inference, and TypeScript emission happen in a dedicated browser worker. Input and generated types are not sent to Data Demon.

Should I choose an interface or type alias?

Interfaces are convenient for extendable object contracts. Type aliases are useful for a consistent alias-based style and are required automatically when the JSON root is an array, scalar, or union.

Why does an empty array become unknown[]?

An empty array provides no element evidence. Add a representative item to the sample or replace unknown with the intended domain type after generation.