JSON to TypeScript type generator prompt
Paste a JSON sample and get accurate TypeScript interfaces, with optional fields and nested types handled correctly.
متى تستخدم هذا البرومبت
- When consuming a third-party API response with no official types.
- When a backend response shape changes and types need updating.
- When scaffolding types before writing a data-fetching hook.
نص البرومبت
Generate {{language}} type definitions from this JSON sample. Use accurate types (no any), mark optional fields, and name the root type {{focus}}.
{{CLIPBOARD}}{{language}}{{focus}}{{CLIPBOARD}}الكتلة {{CLIPBOARD}} تُستبدل تلقائياً بما نسخته قبل الضغط على «نسخ».
كيف تستخدمه
- انسخ البرومبت بالزر أو املأ المتغيرات أولاً.
- الصقه في ChatGPT أو Claude أو Gemini.
- عدّل النتيجة أو أعد الطلب بتغيير المتغيرات.
مثال على النتيجة
interface Address {
street: string;
city: string;
zip?: string;
}
interface User {
id: number;
name: string;
email: string;
address: Address;
tags: string[];
}نصائح للاستخدام
- Paste a real, representative sample response, ideally one with all optional fields present at least once.
- Specify if you want interface vs type to match your codebase's convention.
- If a field can be multiple shapes, note it explicitly so a union type is generated correctly.
أسئلة شائعة
- What if some fields are sometimes null?
- Include a sample with the null value present, or mention it in the focus field, so the type reflects the nullable union correctly.
- Can it also generate a runtime validator, like Zod?
- Yes, ask for a Zod or io-ts schema instead of, or alongside, the plain TypeScript types.