JSON ↔ TypeScript Type Converter
Convert between JSON samples and TypeScript type declarations to draft types and sample JSON.
Category: Converters
When to use?
Use it to quickly draft a TypeScript interface from an API response JSON, or to generate mock JSON data from a TypeScript type declaration.
How to use
- Choose the direction (JSON → TypeScript or TypeScript → JSON).
- Paste the data.
- Copy the converted type declaration or JSON sample.
Input Explanation
Paste the JSON object/array to base the type on, or TypeScript interface code to generate sample data from.
Calculation Basis
For JSON, it recursively traverses the object to infer types (string, number, boolean) and auto-generates an interface; for TypeScript, it parses the AST and generates random dummy data matching the types, returned as JSON.
Usage Examples
- Write API response types - Paste a sample JSON response to draft a TypeScript interface.
- Generate mock data - Generate sample JSON from a TypeScript interface or type declaration.
- Check type definitions - Compare a JSON response against existing type declarations via conversion.
Examples
- {"name": "Kim", "age": 20} → interface Root { name: string; age: number; }
- Paste a TypeScript interface → generate dummy JSON matching the types
Cautions
- Auto-generated types are a draft. Review type accuracy before real use.
- A mismatched encoding standard or complex nested data may break or drop the structure.
Guides
Sample-based type generation
When making TypeScript types from JSON, it infers from the shape of the sample data. Optional fields and varied array shapes must be filled in manually.
Document API responses
Turning recurring API responses into types lets frontend code use autocomplete and type checking.
FAQ
Is it a full schema validator?
No. It drafts based on a sample JSON and type declaration.
Does it handle nested objects?
Yes, nested objects are split into separate interfaces.
Are optional properties shown?
It builds from the sample's properties, so mark optional fields with ? yourself.
Does it infer array types?
Yes. It infers the element type inside an array for an appropriate array type.
Related Tools
- JSON Schema Generator - Generate a JSON Schema draft from a JSON sample.
- JSON Flatten Converter - Flatten nested JSON into a flat key-value structure.
- JSON Formatter - Beautify or minify JSON strings instantly and check for validity errors.
- YAML ↔ JSON Converter - Convert YAML and JSON data bidirectionally in the browser.
- URL Encode / Decode - Encode text into URL-safe form (%XX) or decode an encoded URL back to text.
- Base64 Converter - Encode text to Base64 or decode a Base64 string back to text.