How to Convert JSON to TypeScript
Paste a representative JSON response or open a local .json file. Give the root declaration a useful domain name, choose interfaces or type aliases, and review the inferred nested types. Copy the result into your project or download it as a TypeScript file.
1. Add sample JSON
Use a realistic API response with the fields and array variations your application expects.
2. Choose output options
Set the root name, declaration style, exports, readonly fields, optional fields, and date behavior.
3. Review and export
Check ambiguous types against the API contract, then copy the declarations or download a .ts file.
How Type Inference Works
JSON strings, numbers, booleans, and null values map to matching TypeScript types. Nested objects receive named declarations based on their property names. Arrays use the types found in their sample items; mixed primitive arrays become unions, and object samples are combined into a shared item shape.
| JSON sample | Generated TypeScript | Review note |
|---|---|---|
| "active": true | active: boolean | Direct primitive match |
| "items": [{…}] | items: Item[] | Objects merge into an item declaration |
| "values": [] | values: unknown[] | Empty arrays reveal no item type |
| "note": null | note: null | Revise when the intended nullable type is known |
| Field absent in some array objects | field?: Type | Missing sample fields become optional |
Interfaces, Type Aliases, and Readonly Fields
Interfaces are a familiar choice for object contracts and can participate in declaration merging. Type aliases are equally valid for most generated object shapes and may fit projects that use aliases consistently. The readonly option prevents property reassignment during type checking; it does not freeze runtime JavaScript objects.
Why Generated Types Still Need Review
A sample describes observed values, not the complete API contract. It cannot reveal fields that never appear, every allowed string literal, future response variants, numeric constraints, or whether null represents a wider nullable type. Use generated declarations as a strong starting point, then compare them with official API documentation, schema files, tests, and real responses.
JSON has no native date value. ISO-looking strings stay strings unless date inference is enabled. Choose Date only if application code converts the serialized value before the typed object is used.
TypeScript and JSON References
Learn more from the official TypeScript documentation for object types and interfaces and type aliases. JSON syntax and interoperability are defined by RFC 8259. External references open in a new tab.
Private, Browser-Based Type Generation
JSON parsing, inference, copying, and TypeScript file creation run locally in your browser. Opened files do not need to be uploaded to generate the result. Refreshing the page clears the current workspace.
Continue Your Developer Workflow
Validate and clean the source with the JSON Formatter & Validator, convert configuration data using the YAML ↔ JSON Converter, transform spreadsheet exports with the CSV ↔ JSON Converter, or inspect API tokens in the JWT Decoder & Debugger.
For the wider request-and-response context, read What Is an API?.