DEVELOPER TOOLS

JSON to TypeScript Generator

Turn a JSON example into readable TypeScript interfaces or type aliases, including nested values and optional array fields.

LOCAL TYPE INFERENCE

Generate TypeScript from JSON

Browser-only

Paste one JSON object or array. Arrays of objects are merged so properties absent from some examples become optional.

Your JSON is parsed locally in this browser; nothing is uploaded.

JSON to TypeScript guide

Use a representative JSON response to create a starting TypeScript shape. The generator infers primitive, nullable, nested-object and array types, and combines object examples found in arrays.

What the generator can infer

  • Strings, numbers, booleans and null values become their corresponding TypeScript types.
  • Nested objects receive named declarations; mixed arrays become unions.
  • When array objects omit a key seen in other objects, that property is marked optional.
  • Property names that are not safe TypeScript identifiers are quoted, and the root type name is normalized.

Inference describes only the sample you provide. It cannot discover fields absent from the JSON or prove that a value is always present in other API responses. Review generated types against the source schema and real data.

Choosing a declaration style

Interfaces and type aliases can both describe object shapes. Interfaces are easy to extend; aliases can express unions and other compositions. Empty arrays are emitted as unknown[] because a sample with no elements does not contain enough information to infer an item type.

Frequently asked questions

How are optional properties inferred?

When an array contains multiple objects and a key is missing from some of them, the generated property is marked optional. A single example cannot reveal fields that were never present.

What happens to null values?

A property that is null in the sample is typed as null. If examples contain both null and another value, the generated type is a union such as string | null.

Should I choose interface or type?

Both describe object shapes. Interfaces are convenient to extend; type aliases support unions and other compositions. This tool supports either style for object declarations.

Is my JSON uploaded?

No. JSON parsing and type inference run in this browser. The input is not sent to NAB Tools.

Sources

  1. TypeScript Handbook — Object Types
  2. RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format

Privacy note: JSON parsing and type generation happen locally in your browser. Your sample is not stored or uploaded.