Infer TypeScript interfaces from one or more real JSON samples, with nullable and optional fields derived from the samples and stated assumptions.
Infer TypeScript interfaces from the sample JSON payloads below. This task works from example data; for types designed from requirements or with runtime guards, use a type-design prompt instead. ## Inputs One or more JSON samples of the same payload (more samples reveal optional and nullable fields): [JSON_SAMPLES] Name for the root type: [ROOT_NAME] Naming and style rules (interface vs type, readonly, export): [STYLE] Known facts not visible in the samples (for example "phone may be missing"): [KNOWN_RULES] ## Instructions 1. Derive each property type from the sample values: strings, numbers, booleans, arrays, nested objects and `null`. 2. Compare samples: a key missing from some samples becomes optional (`?`); a key that is sometimes `null` becomes `T | null`. Do not mark fields optional or nullable without evidence or a supplied rule. 3. Extract nested objects that repeat or are reused into named interfaces; keep one-off small objects inline if that matches the style rules. 4. For arrays, merge the shapes of all elements. Use `unknown[]` for empty arrays and say so. 5. Do not narrow strings to literal unions or `Date` unless the known rules say the values are an enum or a parsed date; mention likely candidates instead. 6. TypeScript has one `number` type; note when values look like integers or money that should be validated at runtime. ## Return 1. The TypeScript declarations in one code block. 2. A field notes table: path, inferred type, evidence (which sample), assumption. 3. Fields that need more samples or a schema to type confidently. ## Acceptance checks Each sample must be assignable to the root type under `strict` mode. Do not invent fields that appear in no sample.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Root name: Order
Sample A: {"id":"ord_1001","createdAt":"2026-10-02T09:15:00Z","customer":{"id":42,"email":"a@example.com","phone":null},"items":[{"sku":"MUG-12","quantity":2,"unitPrice":{"amount":18.5,"currency":"USD"}}],"couponCode":null}
Sample B: same shape, but phone is "+1-555-0100", couponCode is "FALL10", and the item has "giftNote":"Happy birthday"
Style: exported interfaces`Money`, `LineItem` and `Order` interfaces where `phone` and `couponCode` are `string | null`, `giftNote` is optional (`giftNote?: string`) because it appears in only one sample, `createdAt` stays `string` with a note that it looks like an ISO 8601 timestamp, and a field-notes table citing which sample supports each nullable/optional choice. Illustrative expectation, not a recorded model run; the reference declarations were compiled locally (see report).
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: