DEBUGGING PLAYBOOK · REVIEWED 2026-10-08

A field exists in only some records

Inferring a type from the first record alone can make every field incorrectly required. This sample shows the difference between absence and null.

Sample input

[{"id":1,"name":"Ada"},{"id":2}]

Steps and checks

  1. Load both records and generate TypeScript.
  2. Check that id is number and name has the optional marker ?. The second record does not contain name.
  3. Add "name":null to the second record and regenerate. name is required with a string | null union, since both records now contain it.

Reference result

export type Root = Array<{
  "id": number;
  "name"?: string;
}>;

Avoid a misleading conclusion

Optional means absent; null is an explicit value. Empty arrays provide no evidence about their future items and infer unknown. A sample cannot describe every possible API response.

What to do next

Review the generated type against the API contract and add missing cases before use. Generated TypeScript does not validate incoming data at runtime.

Related case and technical reference · Report an error or missing edge case

Continue this workflow

Infer optional fields without erasing null from JSON samples →

About this tool

Generate an exportable Root type from sample JSON. Objects in the same array are combined: a field absent from some samples becomes optional, while differing value types become unions. Property names remain quoted to support punctuation and reserved words.

How to use

Generate types from the default two records. id remains number, name and note become optional, tags becomes Array<string>, and note retains null. Add a string note to the second record to observe string | null. Send JSON directly from the formatter without using storage or URL parameters.

Tips & Notes

A sample is not a complete API contract. Dates remain strings; no enums are guessed. Empty arrays use unknown and empty objects use Record<string, unknown>. Duplicate keys and unsafe numbers block conversion. Generation is capped at 32 levels and 10,000 values.