Skip to content
EVOA Toolbox

JSON to TypeScript

Generate TypeScript interfaces or types from a JSON sample. Handles nested objects, arrays, unions, null and optional properties.

Processed locally in your browser. Your text is not uploaded.

Loading tool…

What this tool does

Paste a sample API response or config file and get ready-to-use TypeScript declarations. Nested objects become their own named interfaces, arrays become typed arrays, and null values are typed as null so you can see where a field may be missing.

When an array contains several objects, their shapes are merged: properties present in every element stay required, and properties that only appear in some elements become optional (name?: type). Arrays holding different kinds of values produce unions such as (string | number)[]. Property names that are not valid identifiers, like first-name, are quoted.

You choose the root type name, interface or type alias output, whether to export, and whether to mark properties readonly. Inference runs in your browser on the sample you give it, so the result is only as complete as the sample: review it and loosen types where your API can return other shapes.

How to use it

  1. 1Paste a representative JSON sample (more varied samples give better optional-field detection).
  2. 2Set the root type name and choose interface or type.
  3. 3Toggle export and readonly to match your codebase style.
  4. 4Copy the generated code or download it as types.ts, then review field types against your API contract.

Supported formats

Input: strict JSON. Output: TypeScript declarations (.ts) using interface or type aliases.

Privacy

This tool runs in your browser. The data you provide is processed on your device and is not sent to our servers.

Limitations

  • Types are inferred from one sample only. A field that is always a string in your sample may be a number or null elsewhere.
  • An empty array is typed unknown[] because there is nothing to infer from.
  • Object-like maps (for example keys that are IDs) are generated as fixed properties, not Record<string, T>. Convert those by hand.
  • Dates, UUIDs and enums appear as plain string or number; the tool cannot know their meaning.
  • Numbers are all typed number, including values beyond 2^53 that JSON.parse rounds.

FAQ

How are optional properties decided?

Only by comparing objects inside the same array (or repeated at the same position). If a property is missing from at least one element, it is marked optional. A property that exists with a null value is typed as null (or a union with null), not optional.

Interface or type: which should I pick?

For plain object shapes they are interchangeable. Interfaces can be extended and merged; type aliases work better with unions and mapped types. Pick whichever your codebase already uses.

Why are two nested objects given the same type name?

Objects with identical structure are reused as a single declaration. When two different shapes would get the same name, the second gets a numeric suffix such as Item2.

Is my JSON uploaded?

No. Types are generated in your browser.

Related tools