Skip to content
kivo

JSON to TypeScript

Turn a JSON sample into TypeScript interfaces, with nested objects extracted into their own named types.

Free No signup Runs in your browser — nothing uploaded
Result

What it does

JSON to TypeScript parses the input properly and re-serializes it, rather than pattern-matching its way across. Structure is preserved where the target format can express it, and flattened predictably where it cannot.

When you need it

Moving data between things that disagree about format: an API that answers in one shape, a spreadsheet that only opens another, a config file a tool refuses to read, a export that has to become an import.

Limits and caveats

Formats are not equivalent, so some detail cannot survive the trip — nested structures have to be flattened for tabular output, and comments and type distinctions are lost in both directions. Invalid input is reported rather than guessed at. Everything happens in your browser, so the file never leaves your device.

How to use the JSON to TypeScript

  1. Paste a real response from the API you're typing.
  2. Nested objects become their own interfaces, arrays get element types.
  3. Copy the result into your project.

Frequently asked questions

What happens to arrays of mixed types?
You get a union, e.g. (string | number)[]. Guessing from the first element is how generators produce types that break in production.
Why are null fields marked optional?
Because a null in a sample response almost always means the field can be missing or empty. Turn the switch off if your API really does send null every time.
One sample isn't the whole API.
Correct, and that's the honest limit of this approach. A field absent from your sample can't appear in the types. Paste the fullest response you have.
Do my files get uploaded?
No. This tool runs entirely in your browser, so the file never leaves your device.

Related tools