JSON to TypeScript
Paste a JSON payload and get TypeScript interfaces. Arrays of objects are merged, and missing keys become optional.
How JSON to TypeScript conversion works
Every object becomes an interface, named after its key in PascalCase. When an array contains several objects, their shapes are merged: a property present in some items but not others is marked optional with ?, and properties with different types become a union. Nested objects get their own interface so the output stays readable.
Tips
- Paste a response that contains several array items so optional fields are detected correctly.
- Change the root name to match your domain (for example
UserResponse). - Empty arrays are typed as
unknown[]; tighten them by hand.
Like every tool on TheJSON, this runs entirely in your browser. Nothing you paste is uploaded, logged or stored on a server, so it is safe to use with API responses that contain tokens or customer data.
Frequently asked questions
How does the converter decide a field is optional?
- When an array holds several objects, a key that appears in some of them but not all is emitted with a ? modifier. A key that is present everywhere is required.
What type does a null value get?
- A field that is null in every sample is typed as null. If it is null in some items and a string in others, the result is string | null.
Does it generate types or interfaces?
- Interfaces, one per distinct object shape, because they produce clearer error messages and can be extended. Rename the root with the Root name field.