JSON to TypeScript

Paste a JSON payload and get TypeScript interfaces for it, including every nested object, named sensibly from the keys that hold them. Arrays of objects are merged into a single type covering all their elements, with fields that only appear in some of them marked optional — which matters, because generating a type from just the first element produces something that fails to compile the moment a record omits a field, and that is exactly what most generators do. Mixed arrays become unions, empty arrays become unknown[] so the compiler keeps checking them rather than giving up, and identical shapes are deduplicated instead of producing near-duplicate interfaces. Keys that are not valid identifiers are quoted properly. It runs entirely in your browser, which matters when the payload you are typing is a real API response with real data in it.

How each JSON construct is typed

JSONTypeScriptWhy
{"id": 1}id: number;Direct primitive mapping
{"tags": ["a"]}tags: string[];Element type from the contents
{"v": []}v: unknown[];any[] would disable checking
[{"a":1},{"a":1,"b":2}]b?: number;Missing from one element
{"m": [1, "a"]}m: (number | string)[];Mixed array becomes a union
{"n": null}n: null;Preserved, not dropped
{"kebab-key": 1}"kebab-key": number;Not a valid identifier

When to use it

  1. Type an API response you have a sample of but no schema for.
  2. Generate interfaces for a config file or fixture.
  3. Turn a webhook payload into types before wiring up a handler.
  4. Get a starting point for types you will then refine by hand.
  5. Check which fields are actually optional across a set of records.

How to Use

  1. Paste a JSON object or array.
  2. Set a root type name, and choose interface or type alias.
  3. Read the generated types, with nested interfaces below the root.
  4. Copy them into your project.

Features

  1. Nested interfaces named from their keys, singularised for arrays
  2. Array element shapes merged, not taken from the first element
  3. Optional fields detected across array elements
  4. Unions for mixed arrays, unknown[] for empty ones
  5. Identical shapes deduplicated into one type
  6. Invalid identifiers quoted, reserved words handled
  7. interface or type, export and readonly options
  8. 100% client-side — real API payloads stay private

FAQs

How are optional fields detected?

By comparing every object in an array. If a key appears in some elements but not others, it is marked with a question mark. The more representative your sample, the more accurate that is — a single-element array cannot tell the tool which fields are optional.

Why unknown[] and not any[] for an empty array?

Because an empty array tells you nothing about the element type, and any[] silently switches off type checking for everything downstream. unknown[] keeps the compiler honest and forces you to narrow the type deliberately.

How are nested types named?

After the key that holds them, converted to PascalCase, and singularised for arrays — so a users array produces a User interface and categories produces Category. Identical shapes are deduplicated, so two properties with the same structure share one interface rather than getting two nearly identical ones.

What happens to null values?

Null is kept as a union member and sorted last, so you get string | null rather than the null being silently dropped. If a value is null in your sample but a string in reality, you will need to widen the type yourself — a sample cannot tell the difference.

Should I use the output as-is?

Treat it as a starting point. A sample payload cannot express constraints a real schema has: enums, formats, ranges, or fields that happen to be absent from your sample but exist in the API. It saves the tedious part; the judgement is still yours.

Is my JSON uploaded?

No. Parsing and generation happen in your browser. API responses pasted here — which routinely contain real customer data and tokens — are never sent to a server, logged, or stored.

Technical Details

The JSON is walked depth-first and every object becomes a named interface, with nested types named after the key that holds them, converted to PascalCase and singularised for arrays so a 'users' array yields a 'User' interface. The part that makes the output actually compile is array merging: rather than typing the first element and hoping the rest match, every object in an array is merged into one shape that is the union of all their keys, and any key that does not appear in every element is marked optional. Typing only the first element is the common shortcut and it produces interfaces that fail against the real payload the moment a record omits a field. Mixed-type arrays become parenthesised unions, empty arrays become unknown[] rather than any[] so the compiler keeps checking them, and null is preserved as a union member sorted last for readability. Identical shapes are deduplicated by signature, so two properties with the same structure share one interface instead of producing near-duplicate types. Keys that are not valid TypeScript identifiers — kebab-case, leading digits, embedded spaces — are quoted, and a generated type name that collides with a reserved word is suffixed. All parsing happens locally.

Developer Tools

Developer Tools

  • SQL Formatter
  • CSS Formatter
  • HTML Formatter
  • LLM Token Counter
  • .gitignore Generator
  • Dummy Data Generator
  • RAID Calculator
  • Download Time Calculator