HohoTools

JSON to TypeScript

This free JSON to TypeScript converter turns a JSON sample into ready-to-paste interface definitions the moment you drop it in, entirely in your browser with zero dependencies in the generated code.

How to use

  1. Paste a JSON sample — an API response body works best — into the editor.
  2. Set the root type name if you want something other than RootObject.
  3. Copy the generated interfaces: nested objects become named interfaces, arrays become element types with unions and optional fields where warranted.
  4. Broken JSON reports the exact line and column; fix it and the output regenerates instantly.

Frequently asked questions

How are types inferred?

From your single JSON sample: string, number, boolean and null map directly, nested objects become their own interfaces, and arrays are summarized from their elements. It is a one-sample heuristic, not a precise type system — a field that sometimes holds a number will only come out as number if your sample says so, so feed it a representative payload.

When does a field become optional?

Only for arrays of objects: the elements are merged field by field, and any field that is absent from at least one element is emitted with the optional marker. Within a single object every present field is required, because a lone sample cannot tell a missing field from an impossible one.

How are arrays typed, including empty ones?

Homogeneous arrays keep the element type (string[]), mixed primitives become a union in first-appearance order ((string | number)[]), and arrays of objects become the merged element interface. An empty array carries no type information, so it is honestly emitted as unknown[] instead of a guess.

How are interface names chosen and conflicts handled?

Nested interfaces are named after their parent field, singularized and capitalized (items to Item, categories to Category, address stays Address). Fields keep their original JSON order. If two fields produce the same name, identical shapes share one declaration while different shapes get a numeric suffix such as Address2. Note that integer-like keys are reordered ascending by the JavaScript engine itself.

What happens with invalid JSON?

The tool fails fast: it reports Invalid JSON with the exact line and column from the parser and produces no partial output, so a broken payload can never quietly turn into misleading types.

Is my JSON uploaded anywhere?

No. The inference runs locally in your browser tab; the sample never leaves your device, which makes the tool safe for private API responses.

Related tools

About this tool

This free JSON to TypeScript converter turns a JSON sample into ready-to-paste interface definitions the moment you drop it in, entirely in your browser with zero dependencies in the generated code. Point it at an API response and it maps strings, numbers, booleans and null to their TypeScript counterparts, lifts nested objects into their own interfaces named after the parent field (items becomes Item, address becomes Address), and flattens arrays into element types: homogeneous arrays keep the element type, mixed primitives become a union in first-appearance order, and arrays of objects merge every element so a field missing from even one element is marked optional. An empty array is reported honestly as unknown[] rather than guessed. The root type is configurable (RootObject by default), fields keep their original JSON order, and when two fields produce the same interface name the identical shape is reused while different shapes get a numeric suffix. Invalid JSON fails fast with the exact line and column instead of a half-guess. The inference is a single-sample heuristic, not a precise type system, and the FAQ states every rule plainly — nothing is oversold, and nothing leaves your device.