Generation and Code Structures

JSON → TypeScript

Paste JSON to generate TypeScript interfaces or type aliases.

JSON Input

Generated Code

Merge all sample objects into TypeScript declarations with optional fields, unions, and nested types.

Your JSON and generated code are processed only in your browser, without uploads or automatic saving. Any code in the input is not run.

About This Tool

Generate TypeScript type declarations from sample JSON to review fields, arrays, and nested structures. Every array element contributes to the result, and fields missing from some objects become optional. The output contains type definitions, not the original data values.

How to Use It

  1. Enter valid JSON, preferably an object or an array of objects.
  2. Set the root type name and choose interface or type alias.
  3. Click Convert and review optional ? markers, null unions, and nested types.
  4. Copy the code or download a .ts file named after the normalized root type.

Examples

  • [{"id":1,"name":"Tom"},{"id":2,"email":"a@example.com"}]: id is required; name and email are optional.
  • [1,"a",true]: the element type preserves a union of number, string, and boolean.
  • {"date":"2026-01-01","matrix":[[1,2],[3,4]]}: date stays string and matrix becomes number[][].

Type Mapping Rules

Strings map to string, integers and decimals to number, and booleans to boolean. Missing fields and explicit null values are tracked separately: missing fields get ?, and null alongside a known type adds | null. A null-only sample does not imply a string. Empty arrays use unknown[], and objects get consistently named nested types. Invalid property names are quoted. Root and type names are normalized and deduplicated. Date-like strings remain string. Samples cannot prove that all future data will match the inferred type. Input and output are each limited to 1 MiB, with up to 64 nesting levels, 100,000 nodes, 5,000 merged fields, and 256 types. Unsafe integers, nonfinite numbers, and numbers that underflow to zero produce an error. Other decimals use the browser’s floating-point precision.

Common Uses

  • Draft types from sample API responses.
  • Find fields that may be absent in an object array.
  • Create readable declarations for nested JSON.

Privacy

Your JSON and generated code are processed only in your browser, without uploads or automatic saving. Any code in the input is not run.

If you need to keep the results, copy or download them before leaving the page.

FAQ

Why are date strings not converted to Date?

JSON has no Date type. Date-like strings remain string by default; your application must handle runtime conversion.

How are optional fields identified?

A field becomes optional when it is present in some sample objects but missing from others. Include several representative samples to reflect the fields more accurately.

How does explicit null differ from a missing field?

A null field exists with a null value; a missing field does not exist. Type unions and optional markers represent these separately.

What if array elements have different types?

Compatible object shapes are merged, integers and decimals become number, and heterogeneous primitive types form unions.

Is the output a complete data validator?

No. TypeScript declarations describe static types. They do not validate JSON at runtime or infer cases absent from the sample.

Back to Developer Tools