AWS cron generator
Cron generator
Text counter
JSON to CSV converter
CSV to JSON converter
Unix timestamp converter
UUID v4 and v7 generator
JSON to TypeScript converter
Markdown to PDF
Base64
Images
JSON
QR Code
Passwords
Units
Hash
Colors
PDF Tools
PDF Editor
URL Encoder
Case Converter
Lorem Ipsum
Regex Tester
JWT Decoder
Text Diff
SVG Optimizer
EXIF Viewer
Color Extractor
Favicon Generator
Universal Converter
Hours Converter
PDF Splitter
Images to PDF
PDF to Image
Background Remover
Developer Tools

JSON to TypeScript converter

Infer TypeScript declarations from a JSON sample, including unions, optional properties and nested objects. Review the generated code before adopting it as an API contract.

On your device

Files and text are processed in your browser.

Privacy Policy
JSON → TypeScriptProcessed in this browser. No data is uploaded or saved.

Maximum 200 KiB UTF-8; nesting limit: 50 levels.

.ts

For an array or primitive root, interface mode emits a root type alias.

Types describe only the sample. Missing properties become optional; null remains explicit; empty arrays use unknown[]. This does not validate data at runtime.

How to use this tool

  1. Input

    Paste valid JSON or load the synthetic example. Include representative variants of the structure you want to describe.

  2. Options

    Enter a valid root name, such as ApiResponse, and choose interface or type. Non-object roots use a type alias.

  3. Result

    Select Convert, review optional properties and unions, then copy or download the .ts file. Check it with your compiler.

Worked example

Worked example · JSON to TypeScript converter

The second record has active but the first does not, so active is optional. Both observed tag types appear in the union.

Input

[{"id":1,"tag":"x"},{"id":2,"tag":null,"active":true}]

Result

export type ApiResponse = ({
  active?: boolean;
  id: number;
  tag: null | string;
})[];

Options: ApiResponse · type

Formats and limits

Limits
Maximum 200 KiB UTF-8; nesting limit: 50 levels.
Options
Both describe objects. Type emits an alias; interface emits an interface for an object root. An array or primitive root requires an alias even in interface mode.
Result
All objects in the same array are compared. A property missing from any object is marked with ?. A null value is different from an absent property.

Common issues

What happens to null and empty arrays?

Null remains an explicit type and may appear in a union. An empty array becomes unknown[] because there are no elements to infer from.

Does this validate data at runtime?

No. TypeScript checks types during development; these declarations do not inspect future API responses. Add a runtime validator when needed.

JSON to TypeScript converter

Infer TypeScript declarations from a JSON sample, including unions, optional properties and nested objects. Review the generated code before adopting it as an API contract.

Review the result before using it

The second record has active but the first does not, so active is optional. Both observed tag types appear in the union.

Formats and limits

Maximum 200 KiB UTF-8; nesting limit: 50 levels. Processed in this browser. No data is uploaded or saved.

Frequently Asked Questions

Should I choose interface or type?

Both describe objects. Type emits an alias; interface emits an interface for an object root. An array or primitive root requires an alias even in interface mode.

How are optional properties detected?

All objects in the same array are compared. A property missing from any object is marked with ?. A null value is different from an absent property.

What happens to null and empty arrays?

Null remains an explicit type and may appear in a union. An empty array becomes unknown[] because there are no elements to infer from.

Does this validate data at runtime?

No. TypeScript checks types during development; these declarations do not inspect future API responses. Add a runtime validator when needed.

What if the sample is incomplete?

The result only knows the values provided. It does not discover future fields, business rules, dates or enums. Use varied samples and review the actual contract.