Convert a pasted JSON payload into typed interfaces

Turn raw API JSON responses into clean, strongly typed TypeScript interfaces with optional field detection.

You getTypeScript Interfaces and field Assumptions

Prompt

Prompt
You are a senior frontend engineer converting raw JSON data into type-safe code structures.
- Infer exact primitive types (string, number, boolean, null) from the provided JSON.
- Split nested objects and arrays into distinct, cleanly named top-level interfaces.
- Detect likely optional fields where values are null or likely variable across API responses and mark them with a question mark.
- Use idiomatic PascalCase for interface names and camelCase for property names.

Output format:
- TypeScript Interfaces (in a single typescript code block)
- Field Assumptions (bulleted list of inferred optionality or type unions)

The JSON payload is below:

Example output

Example for: raw API payload of a customer invoice

TypeScript Interfaces
export interface InvoiceItem {
  id: string;
  description: string;
  quantity: number;
  unitPriceCents: number;
  discountPercent?: number | null;
}

export interface CustomerAddress {
  street: string;
  city: string;
  postalCode: string;
  countryCode: string;
}

export interface Customer {
  id: string;
  name: string;
  email: string;
  address: CustomerAddress;
}

export interface Invoice {
  invoiceId: string;
  invoiceNumber: string;
  issuedAt: string;
  paidAt?: string | null;
  customer: Customer;
  items: InvoiceItem[];
  subtotalCents: number;
  taxCents: number;
  totalCents: number;
}
Field Assumptions
  • paidAt is marked optional with a union to null because unpaid invoices frequently omit or zero-value this timestamp.
  • discountPercent is flagged optional as itemized line discounts may not exist on every product.
  • Numeric money fields are inferred as integer cent amounts rather than floating-point values.
Written by AI from this prompt. Your results will vary.

Paste this prompt into ChatGPT, Claude, or Gemini, then paste your raw API JSON response after the final line. Ask the model to convert the output into Pydantic models, Go structs, or Swift Codable if you use another backend language.

Make it repeatable

Keep using this prompt without pasting it in every time.

Keep exploring

More in Coding