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.
Type generation
Compare the two sample records, then try your response. Switch to Schema input when you have an explicit contract.
Parsed and generated in this browser. Input is not uploaded or stored.
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.
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.
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.
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.
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.
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.
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[].
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.
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.
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.
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.
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.
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.
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.
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?
Use JSON to TypeScript with several response variants, inspect the optional and nullable fields, then copy or download the declarations for review.