Skip to content
Simple Tools

JSON to TypeScript type generator

Infer a Data type declaration from a JSON sample, with array unions and explicit limitations.

Enter data

One JSON document, up to 32 levels for type generation. Fields marked with an asterisk are required.

Up to 50,000 UTF-16 units. Content is not uploaded or saved.

About this tool

An API response sample can provide a starting point for TypeScript types. Values become primitive types, nested object shapes are retained and differing array items form a union. The complete API contract is unknown: absent fields, ranges and other possible responses require separate review. Output is working material, not a validator for data at runtime.

How to use the calculator

  1. Paste a representative anonymized JSON sample.
  2. Select “Process” and copy the Data declaration into a .ts file.
  3. Check the type with your compiler and API documentation. Review optionality and add runtime validation separately.

Calculation details

Formula and calculation method

String → string, number → number, boolean → boolean, null → null. Objects have quoted required members. Arrays contain a union of distinct inferred types. Empty array → unknown[]; empty object → Record<string, never>.

Worked example

Sample {"id":1,"tags":["a",2],"note":null} gives Data with "id": number, "tags": Array<string | number> and "note": null. The tool does not assume note can also be a string because the sample does not demonstrate that.

Limitations

  • JSON: 50,000 UTF-16 units, 64 container levels and 10,000 values. Duplicate member names and unpaired Unicode surrogates are rejected. No JSON5, comments, JSON Lines or file import.
  • Type generation: 32 levels, up to 64 distinct shapes per array and 500,000 output UTF-16 units. Differing array objects form a union, not one interface with optional members. Members are required in each observed shape.
  • No date, enum or business-format detection, JSON Schema or code execution. TypeScript number does not guarantee large-number precision. An empty object is modeled as having no members, a narrower assumption than a general API object.

Sources

Frequently asked questions

Does output validate an API at runtime?

No. A type declaration performs no validation. Check the API response with a separate runtime validator or schema.

Why does null not become string | null?

The sample demonstrates only null. Establish other permitted types from the API contract.

How is an empty array handled?

It becomes unknown[] because there are no items to infer from. The tool does not use any[].

Is data uploaded?

Inputs and results are not sent to a server or analytics or saved in the URL or persistent form storage. Reset does not remove previous clipboard copies, printouts or data held by browser extensions. Do not paste secrets.

Read the supporting guide

Generator

JSON to CSV converter

Convert a flat JSON object array to CSV or TSV, with explicit rules for empty cells and formula-like text.

Open tool
Generator

CSV to JSON converter

Convert CSV or TSV with a header to a JSON object array without guessing cell types.

Open tool
Calculator

Unix timestamp converter

Convert Unix seconds or milliseconds to UTC and Warsaw time, or an explicitly offset date to a timestamp.

Open tool