TXT · Text & Data tools

JSON to TypeScript Converter

Top-level type
Acronyms
JSON input
TypeScript output
Inference
TypeScriptlanguageJSON sampleinput0types0lines out0chars out
Go to the full JSON to Types generator with all ten languages

Shareable link

Settings are written to the URL as you change them. Nothing differs from the defaults yet.

TypeScript from a JSON sample

Paste the response body and get the interfaces for it. Objects become interfaces, arrays become T[], a key missing from some objects in an array becomes an optional member, and null values stay null until a second sample widens them.

Interfaces, types, readonly

Three checkboxes shape the declarations. type instead of interface switches every declaration to a type alias. readonly members adds readonly to each property, which is the right default for data that comes off the wire and should never be mutated in place. Name unions gives each inferred union its own alias instead of inlining string | number at every use.

Runtime checking

With Types only unchecked, the output ends in a Convert class. Convert.toCustomer(json) parses a string and walks the result against the type, throwing with the property path when a value does not match. That turns a compile-time assumption into a runtime guarantee at the boundary where the JSON arrives. Uncheck Runtime type check to keep the class as plain JSON.parse wrappers, or check Types only to drop it.

Example

{ "user_id": 12, "roles": ["admin", "editor"], "last_login": "2025-04-01T10:00:00Z" }

With camelCase properties on and dates inferred:

export interface Root {
    userId:    number;
    roles:     string[];
    lastLogin: Date;
}

The Convert class, when included, maps userId back to user_id on serialization.

Limits

TypeScript has no integer type, so every number is number. A string that contains only digits is inferred as a number unless Integers from numeric strings is turned off under Inference, which is the right setting for postal codes and ids.

Frequently Asked Questions

Interfaces by default. Check type instead of interface to emit type aliases, which matters when you want to use the declarations in unions or mapped types.

A set of toX and xToJson functions that parse a JSON string and check every property against the generated type at runtime, throwing on a mismatch. Check Types only to leave it out.

Repeated string values across many objects are inferred as an enum, and TypeScript renders enums as unions of string literals by default. Uncheck Unions instead of enums for an enum declaration, or turn off enum inference entirely.

Yes. camelCase properties rewrites snake_case keys to camelCase in the interface, and the Convert class maps them back to the original JSON keys when parsing and serializing.

Values whose type cannot be determined, such as an empty array or a field that is always null, are typed unknown rather than any, so the compiler forces a check before use.

Generate types for one language

Full JSON to Types Generator tool

Explore Our Tools

Browse all tools