Skip to content
Hakoro

JSON to TypeScript

New

Generate TypeScript interfaces from a JSON sample: nested types, optional fields and unions worked out for you. Free, private, in your browser.

Runs in your browser. Nothing you enter is uploaded

Loading tool…

About JSON to TypeScript

Paste an API response or any JSON sample to get TypeScript declarations that describe it. Nested objects get their own named interfaces, and arrays of objects are merged: fields missing from some items become optional, and fields with mixed types become unions.

Identical shapes are declared once and reused, and names come from your keys, so users becomes User[]. The JSON is processed in your browser and never uploaded, which matters for responses that contain real customer data.

How to use JSON to TypeScript

  1. 1Paste JSON or open a .json file.
  2. 2Name the root type and choose interface or type, with or without export.
  3. 3Copy the declarations into your code or download them.

Frequently asked questions

Is my JSON uploaded?

No. The types are generated in your browser, so nothing you paste leaves your device.

How are optional fields detected?

When an array contains several objects, a field that's missing from some of them is marked optional (?). The more varied the sample, the more accurate the types.

What happens with null values?

null becomes part of the type, for example string | null. A field that's only ever null is typed as null: add a sample with a real value for a more useful type.

Interface or type?

Both describe the same shape. Interfaces can be extended and merged, and type aliases are handy with unions. Pick whichever your codebase uses.