JSON to TypeScript
Turn a JSON sample into ready-to-paste TypeScript interfaces. Arrays, nested objects, nulls and mixed types are handled automatically.
How it works and known limits
How types are inferred
The generator parses your JSON, then walks the value tree. Strings become string, numbers become number, booleans become boolean and null becomes null. Arrays of objects produce an element interface named after the field, and the field is typed as an array of that interface. Empty arrays become unknown[].
Handling mixed and nullable values
When an array contains objects with different keys, the generator merges the keys and marks fields that are missing in some items as optional with a question mark. A field that is sometimes null is emitted as a union with null so the type matches the sample.
Known limits
Type inference reflects only the sample you paste, not the full domain of your data. A field that is a number in the sample is typed number even if production sometimes sends a string. Review generated interfaces before committing them, and widen a type when your API contract allows more than one shape.
How to generate TypeScript types from JSON (with screenshots)
Paste a JSON sample and get TypeScript interfaces describing its shape — useful for typing API responses.
Open the JSON to TypeScript
Open the JSON to TypeScript page. The json sample is where your work begins; the result appears on the right.
Enter your input
Paste a representative JSON object into the input box. Include nested objects and arrays for richer types.
Run the tool
Click Generate types to build the interfaces. An exported interface is generated for the root and every nested object, plus a Root type alias.
Tip: Inspect the generated types before using them — one JSON sample cannot reveal optional fields.
Frequently asked questions
Does this upload my JSON?
No. Parsing and interface generation run entirely in your browser with plain JavaScript.
Are nested objects supported?
Yes. Nested objects become separate named interfaces and the parent field references them.
What type does an empty array get?
Empty arrays are emitted as unknown[] because there is no element to infer a type from.
Is the output valid TypeScript?
Yes. The generated interfaces use standard type syntax and can be pasted into any TypeScript file.
Page last reviewed: