How to Convert JSON to TypeScript Types
March 22, 2026 · 7 min read
You've got a JSON response from an API. You need TypeScript types for it. You could write them by hand, but that's tedious and error-prone — especially for deeply nested objects with dozens of fields. Here's how to convert JSON to TypeScript interfaces quickly and correctly.
Why You Need TypeScript Types for JSON
Without types, your API response is any — which means TypeScript can't catch property name typos, missing fields, or type mismatches. Adding proper interfaces gives you:
- Autocomplete — your editor knows every field and its type
- Compile-time errors — catch user.nmae typos before they become runtime bugs
- Refactoring safety — rename a field and see every place it's used
- Documentation — interfaces serve as living API documentation
Method 1: Use an Online Converter
The fastest way — paste your JSON and get TypeScript interfaces instantly.
Paste any JSON object to generate TypeScript interfaces automatically.
Open JSON to TypeScript ConverterMethod 2: Manual Conversion
Understanding the manual process helps you write better types. Here's a JSON object and its TypeScript equivalent:
The JSON
The TypeScript Interface
JSON-to-TypeScript Type Mapping
- 42 (number) → number
- "hello" (string) → string
- true/false → boolean
- [1, 2, 3] → number[]
- ["a", "b"] → string[]
- [1, "a"] (mixed) → (number | string)[]
- {...} (nested object) → separate interface
- null → null (or unknown | null if unsure)
Method 3: quicktype (CLI)
quicktype is the gold standard for generating types from JSON. It handles edge cases like optional fields, union types, and deeply nested structures:
quicktype is smart — give it multiple JSON samples and it will infer optional fields and union types:
Method 4: In Your Editor (VS Code)
Several VS Code extensions can generate TypeScript interfaces from JSON:
- Paste JSON as Code — Select "Paste JSON as TypeScript" from the command palette
- JSON to TS — Right-click in a .ts file, select "Convert JSON to TypeScript"
Or use the built-in approach — create a temporary .ts file and let TypeScript infer:
Handling Common Edge Cases
Optional Fields
If some fields aren't always present in the API response, mark them optional:
Union Types (Multiple Possible Shapes)
Date Strings
JSON doesn't have a date type — dates come as strings. Use a branded type for clarity:
Dynamic Keys
Interface vs. Type — Which to Use?
Both work for JSON conversion. The practical differences:
- Use interface for object shapes — they can be extended and merged, and produce clearer error messages.
- Use type for unions, intersections, and computed types.
- For simple JSON-to-TypeScript conversion, interface is the conventional choice.
Best Practices
- Don't use any — the whole point is type safety. Use unknown if you genuinely don't know the type.
- Generate from real API responses — don't guess the shape. Hit the endpoint, copy the response, convert it.
- Keep types in sync — if the API changes, regenerate. Consider using quicktype in CI to catch drift.
- Validate at runtime too — TypeScript types are erased at runtime. Use zod or io-ts to validate API responses match your types.
Try It Now
Got a JSON response you need types for? Use the free JSON to TypeScript converter on UtilShed — paste your JSON and get interfaces instantly.
Related tools:
- JSON Formatter — pretty-print your JSON before converting
- JSON Validator — make sure your JSON is valid first
- TypeScript Formatter — format the generated interfaces
- JSON to YAML Converter — for config file conversions