JSON to TypeScript Converter

Paste a JSON sample to generate a TypeScript type for its nested objects and arrays. Copy or download the result, then refine optional fields and unions by hand. Everything runs in your browser and your input stays on this device.

What this tool does

Infer a draft type alias for one JSON sample, including nested properties and inferred array element types.

Type alias or interface?

The output is an exported type alias. For plain object shapes a type alias and an interface behave almost identically, so you can rewrite it as an interface if that is your codebase’s style. The type reflects only the sample you paste, so compare several real responses before relying on it.

When to use it

Start modeling a new API without typing every observed field by hand. Review optional fields and other response variants before using the type.

How to use it

  1. Paste a representative JSON body without secrets.
  2. Select Generate TypeScript and copy the Root type.
  3. Rename it and refine nullability, optional keys and unions against your contract.

If the sample won’t parse, check it with the JSON Validator first.

Worked example

Convert {"id":1,"label":"demo","tags":["api","test"],"metadata":null}. The output describes id as a number, label as a string, tags as an array of strings and metadata as null. Copy the Root type into a TypeScript file and rename it to match your domain, such as ItemResponse. If production examples show metadata as an object as well, update that property to describe both possibilities. Compare several representative payloads before committing a type generated from just one response.

Example input
{"id":1,"tags":["api"]}
Example output
export type Root = {
  "id": number;
  "tags": Array<string>;
};

Supported features and limitations

The type reflects the example alone. Add optional properties by hand where needed. Empty arrays become Array<unknown>. The generated type provides compile-time checks.

Common mistakes and edge cases

An empty array has no elements to infer from and becomes Array<unknown>. A missing property in the input is absent from the output, while a property explicitly set to null gets the null type. Mark keys optional when API documentation says they may be omitted. Review mixed arrays and decide whether the union describes real variation or an upstream data issue. Preserve property spelling if the TypeScript type represents the network format. If your API represents several variants with a shared discriminator, generate a draft for each variant separately. Then use the discriminator to describe the union explicitly so code can narrow the type when it reads that field.

Frequently asked questions

Does a generated type validate incoming data at runtime?
TypeScript types help the compiler check your source. Data that arrives over the network still needs runtime validation when correctness depends on its shape. Use the API contract and a runtime parser where appropriate.
Why are property names quoted?
Quoted property names also cover valid JSON keys such as user-id or display name, which cannot be written as ordinary TypeScript identifiers. The resulting type preserves those names so property access matches the source data.
How are empty arrays and null handled?
An empty array has nothing to infer from and becomes Array<unknown>. A property set to null gets the null type, and a property missing from the sample is absent from the output.
Does it mark properties as optional?
No. It describes only what appears in your sample. Mark keys optional by hand when your API documentation says they can be omitted.
Can I get an interface instead of a type?
The tool generates a type alias. For object shapes, replace “export type Root = {” with “export interface Root {”.
Is my JSON uploaded anywhere?
No. The text is processed in your browser and stays on your device.

Related tools

Developer guides