JSON to TypeScript
Generate TypeScript interfaces or type aliases from sample JSON, merging array items into optional properties and union types.
0 characters · 1 line
Types are inferred from the sample: properties missing from some array items become optional (?), and cases the sample does not show are not included.
How to use
- Paste a JSON sample, such as an API response, on the left, or click “Example”.
- Set the root type name, choose interface or type declarations, and whether to add export and readonly.
- The TypeScript types appear instantly on the right (below on phones). Click “Copy” or “Download” for a .ts file.
FAQ
Is my data uploaded?
No. The types are generated in your browser and your JSON never leaves your device, so pasting API responses with personal data is fine.
What if objects in an array have different properties?
All elements of an array are merged into one type: properties that appear only in some elements become optional (name?: string), and a property with different types in different elements becomes a union (number | string).
What type does null become?
By default it joins the union, as in string | null; a property that is only ever null is typed null. With “Make null properties optional”, it becomes name?: string instead, which suits APIs that use null for “no value”.
How are nested types named?
After the property, in PascalCase: user_profile becomes UserProfile. Array items use the singular, so items of users are called User, or get an Item suffix when there is no plural to remove. Objects with exactly the same structure share one type; different structures with the same name get a number (Item2).
Why are some property names quoted?
Names that are not valid JavaScript identifiers (with - or spaces, or starting with a digit) must be quoted, as in "first-name": string. Chinese property names are valid identifiers and stay unquoted.
What about big numbers and dates?
JSON only has numbers and strings, so numbers beyond the safe integer range are still number and date strings are still string. Change them to bigint or Date by hand if you need to.
Related tools
JSON Formatter
Beautify, minify and validate JSON with precise line and column error locations.JSON Viewer
Browse JSON as a collapsible tree, search keys and values, and copy any node’s JSONPath or value. Handles large files.Case Converter
Convert text to UPPERCASE, lowercase, Title Case, Sentence case, camelCase, PascalCase, snake_case, kebab-case and more, all at once.