JSON to TypeScript
Turn one JSON sample into a readable TypeScript type. Inspect what the sample proves and where its shape remains unknown.
Up to 100,000 UTF-8 bytes, 10,000 values and 40 nesting levels. Ctrl/Cmd + Enter generates the type. Processing stays in your browser. Jobs stop after three seconds.
Example input is ready. Run the tool to produce a result.
Infer types from the values you can see
JSON describes values; a TypeScript type describes a set of values. This converter reads strict JSON and maps strings, numbers, booleans and null to their TypeScript counterparts. Nested objects become nested object types. It generates a single exported type alias that you can copy or download and then refine in your project.
How to generate a type
- Paste a representative JSON object, array or primitive.
- Choose a root type name using ASCII letters, digits, underscore or dollar sign. Start with a letter, underscore or dollar sign, and avoid reserved words. Array and Record are reserved here because the output uses those built-in helpers.
- Select Generate type. Review the inferred shape and any warnings.
- Copy the exact TypeScript output or download sample-types.ts. Add domain constraints and runtime validation separately.
Mixed arrays and missing properties
Arrays collect distinct observed shapes into a union. For example, an array containing a string and null becomes Array<string | null>. Objects with different property sets stay separate union members. A property missing from another object does not automatically become optional, and fields present in the sample remain required within that observed object type. Property order is sorted for stable output; equivalent shapes are deduplicated.
Empty values and unusual keys
An empty array becomes unknown[] because it contains no evidence about its items. An empty object becomes Record<string, unknown> because it supplies no known properties. JSON keys that are not plain ASCII identifiers are emitted as quoted, escaped property names. A null value stays null instead of being guessed as another type. The output does not infer literal enums, date types, tuples, optional properties, branded IDs or reusable named interfaces.
Syntax, limits and precision
Comments, trailing commas and duplicate object keys are rejected. The input limit is 100,000 UTF-8 bytes, 10,000 values and 40 nesting levels. An array supports up to 32 distinct item shapes; shape comparison has a two-million-character work limit. Output is capped at 250,000 characters and a worker stops after three seconds. Numeric tokens infer number, including large numeric samples; the output describes a JavaScript number type and does not preserve or validate numeric precision.
Is the generated type a validator?
No. Type annotations do not validate a server response or other runtime input. One example also cannot establish every shape that future data may take. Review a broader set of examples, decide which properties are optional in your domain, and use a runtime schema when untrusted values need validation.
Does local processing guarantee offline use?
Your pasted input is processed in your browser and is not sent to a server for analysis. The page still needs its editor and worker files. Starting a new job can require network access even after an earlier successful run, depending on browser caching and server settings. If a worker asset cannot load, the tool clears the old result and reports an error. Restore access and run the tool again. This tool does not install an offline cache or guarantee offline availability.
Reference
The TypeScript handbook on everyday types explains object types, arrays, unions and optional properties. This tool deliberately keeps inference conservative and visible.