Data & CSV

JSON to TypeScript

JSON to TypeScript

Generate TypeScript interfaces or a Zod schema from JSON, with optional fields inferred.

About this tool

About JSON to TypeScript

Typing an API response by hand is slow and the result drifts from reality. Paste a real response and get TypeScript interfaces back. Nested objects become their own named types, taken from their keys, so a customer object becomes Customer and an items array becomes Item[]; objects with identical shapes share one type instead of being repeated. When you paste an array of records, or several samples one per line, every item is merged: keys that are missing from some records become optional, values that are sometimes null get | null, and mixed values become unions. Choose interface or type declarations, set the root name, and toggle export, readonly and optional markers. Switch Output to Zod to get a runtime schema with z.object, .nullable() and .optional(), declared in dependency order with an inferred type for each, ready to validate responses at runtime. Keys that aren't valid identifiers are quoted. It all runs in your browser. An optional AI pass, using your own key, refines names, unions and doc comments.

Built and maintained by Abhi JainUpdated

How to Convert JSON to TypeScript

  1. 1

    Paste JSON

    Paste a JSON object, an array of objects, or one JSON document per line into the JSON pane.

  2. 2

    Set the options

    Choose TypeScript or Zod output, set the Root name, and pick interface or type, Export, Readonly and Optional.

  3. 3

    Copy the types

    Copy the generated code or download it as types.ts (schema.ts for Zod output).

JSON to TypeScript: questions and answers

How are optional fields detected?

All objects found at the same place, such as every item of an array or every sample you paste, are merged. A key that is missing from at least one of them is marked optional with ?.

Should I use interface or type?

Both work for object shapes. Interfaces can be extended and merged, and their errors read a little better; type aliases can express unions. Many teams pick one style for consistency, so both are offered.

What is the Zod output for?

TypeScript types disappear at runtime. A Zod schema validates real data, for example an API response, and z.infer gives you the matching TypeScript type from the same definition.

Why is a field typed as unknown[]?

The sample only had an empty array there, so the item type can't be known. Paste a sample where the array has items, or edit the type by hand.

Is my JSON uploaded?

No. Types are generated in your browser.

Can AI refine the generated types?

Yes. Click AI to get better type names, string-literal unions and doc comments, guided by notes you type. The JSON sample and generated code are sent. It's optional and uses your own AI key (Claude, OpenAI, Gemini, DeepSeek, OpenRouter or a compatible endpoint), sent straight from your browser to that provider; KissThePDF never sees it. Without a key the tool works exactly the same.