Type generation

JSON to TypeScripttypes shaped by your actual data

Compare the two sample records, then try your response. Switch to Schema input when you have an explicit contract.

JSON to TypeScript

JSON input

Parsed and generated in this browser. Input is not uploaded or stored.

TypeScript result

Generation options

Missing fields become optional; null stays null. Empty arrays become unknown[]. Use strictNullChecks in your project.

3 declarations · 1 optional properties

JSON to TypeScript helps turn an API response into an initial model. A single successful response can hide fields that disappear later, so include several representative records in one array before relying on the result.

The preview separates missing properties from explicit null values. Generated declarations give you a starting point to review in your project; they do not establish what every future response will contain.

Why use JSON to TypeScript here?

Combine records before declaring fields

JSON to TypeScript examines every supplied array element. If one record lacks a tag, that field becomes optional; if a score is sometimes null, its type includes null. Those two changes describe different data and remain visible in the preview.

Two records merge into one type: a missing field has a dashed marker while an explicit null keeps a hollow marker.

Use a contract when samples are incomplete

A Schema can declare required fields and allowed enum values that a sample cannot reveal. Select the auxiliary mode explicitly. Unsupported assertions stop conversion with a path, so the generated declarations do not silently leave those instructions out.

Sample records and a structured contract feed separate paths toward a shared set of type declaration cards.

Read the differences before you export

01

Supply variants at the same position

Place several records in one JSON array. Fields are compared between objects at that position; unrelated objects elsewhere in the document are not merged simply because a property name matches.

02

Choose the source mode before loading an example

Changing the mode keeps your input. The Example button then loads a sample for the selected mode. Schema required controls optional fields there; the all-optional checkbox affects only sample inference.

03

Refresh after changing names or options

Automatic generation waits 350 ms after edits. Turn it off to reveal Generate, or use Ctrl/Cmd+Enter. Editing immediately disables export until a current result succeeds. Choose interface for object declarations or type for aliases.

From sample values to named declarations

All elements contribute to type inference

Numbers and strings at the same position produce a union. Nested arrays are analyzed across their elements, and an empty array borrows evidence from nonempty arrays at the same position. With no element evidence, the result is unknown[].

Optional does not mean nullable

A property missing from some records gets ?. A present value of null produces null or a union containing null. A field seen only as null cannot reveal a hidden string or number type. Enable strictNullChecks in your project to keep that distinction useful.

Names for nested objects

The root name defaults to Root. Nested names derive from their containing fields, with stable suffixes for collisions. Original property spelling stays intact, including spaces and hyphens through quoted keys. Root names accept ASCII identifiers up to 64 characters, excluding reserved words.

A bounded JSON Schema to TypeScript mode

Supported constructs include boolean schemas, type, properties, required, single-schema items, boolean additionalProperties and scalar enum/const. anyOf allows annotation siblings only. Integer becomes number. JSON to types here emits declarations, not parsing functions; export and two- or four-space indentation are configurable.

What the output can and cannot promise

A sample is evidence, not the entire contract
Only supplied values inform inference. Objects in an array are merged by field, so relationships between discriminator values and other fields are not preserved. Strings are widened to string; dates, UUIDs and enum sets are not guessed.
Static types do not validate responses
This TypeScript interface generator emits no runtime checks, classes, Zod schemas or serializers. number does not enforce integer precision. additionalProperties=false omits an index signature, but TypeScript structural typing does not guarantee exact objects at runtime.
Schema assertions must be supported
References, definitions, oneOf/allOf, conditionals, formats, patterns, ranges and tuple schemas are rejected. Object or array keywords require an explicit matching type. Schema-valued additionalProperties and object/array enum values are unsupported. Numeric literals that overflow or exceed safe magnitude are rejected.
Strict, single-document input
Comments, trailing commas, JSONL and duplicate object keys stop conversion. JSON syntax errors include line and column. There is no repair, URL fetch, file import or batch workflow. Schema is never detected automatically from the presence of a type property.
Limits stop the whole conversion
The budgets are 500,000 input characters, depth 100, 50,000 nodes, 1,000,000 output characters and 1,000 declarations. Exceeding a budget prevents export instead of truncating code. Empty objects without evidence use an unknown index signature rather than the overly broad {} type.

JSON to TypeScript questions

Does it generate interfaces or type aliases?

Both declaration styles are available. interface applies to object declarations; an array, primitive or union at the root still needs a type alias. Changing the option updates nested object declarations too.

How are arrays of objects with different keys handled?

All objects at that array position contribute fields. A key absent from any of them becomes optional, while observed value types form a union. Add realistic variants before using the model; one record cannot demonstrate missing keys.

Why do the generated types have unusual names?

Names are derived from the root and containing property, normalized into valid identifiers, then given suffixes if necessary. JSON to TypeScript cannot infer your domain vocabulary; rename Root before generating, and review nested names in your editor.

Why is no code generated when I paste JSON?

Check the error beneath the options. Duplicate keys, strict syntax errors, an invalid root name or a budget limit prevent a fresh result. In Schema mode, unsupported keywords also stop generation; select JSON sample mode for ordinary data.

Can these types parse JSON and verify its type?

No. TypeScript declarations disappear from runtime JavaScript. Parse and validate incoming data separately with a runtime validator appropriate to your application; assigning or asserting a TypeScript type is not a data check.

Found an inference case worth checking?

Start with a representative response

Use JSON to TypeScript with several response variants, inspect the optional and nullable fields, then copy or download the declarations for review.