By Debmedia Technologies LLP · Kolkata, India · Updated
What Is It and When Do You Need It?
Writing TypeScript types by hand for an API response is slow. A converter reads a real sample and writes the types for you, including nested objects, which you then tidy up.
Paste a JSON sample and copy the generated types.
How to Use This Tool
- Paste valid JSON.
- Optionally name the root type.
- Choose interface or type.
- Press Convert and copy the result.
How the Calculation Works
The tool walks the JSON. Strings, numbers and booleans become string, number and boolean. Null becomes null. Objects become named interfaces, using the key name in PascalCase. Arrays of objects are merged into one interface with optional keys where needed. Arrays with mixed items become unions.
Worked Example
The JSON {"id": 1, "tags": ["a"]} gives an interface Root with id: number; and tags: string[];.
Common Uses
- Typing API responses.
- Config files.
- Mock data.
- Migrating JavaScript to TypeScript.
Tips and Common Mistakes
- Use a sample with every field present.
- Review numbers that may be strings in other responses.
- Check dates, which JSON stores as strings.
- For arrays, include several different items in your sample so the tool can see which fields are optional and which values can be null.
Related Tools
Next, you may need the SQL IN clause generator, string escape tool, query string parser, Markdown table generator.
Everything runs in your browser. Nothing you type is uploaded, stored or sent to any outside service.
Frequently Asked Questions
Disclaimer: results are calculated in your browser from the numbers you enter. Check important results before you rely on them for money, health, safety or legal decisions.