Data / LOCAL TOOL

JSON to Types

Infer TypeScript, Go, or Python data models from a JSON sample locally.

Runs locally — input is never uploaded
Paste or drop a JSON sample
Ready when you are

WHAT IT DOES

Turn the sample response into the types that have to receive it.

Paste one JSON value or an array of representative objects and choose TypeScript, Go, or Python. The tool walks the observed structure, gives nested objects stable names, merges array samples, marks fields that are absent from some samples as optional, and preserves nullability and mixed values where the target can express them. It generates only what the sample establishes and reports the places where a real contract may need a broader type.

Why use it?

Use representative API responses to draft types, then review what the examples could not establish. A successful response alone says nothing about error payloads or missing fields.

How to use this tool

  1. Paste a JSON sample or an array containing several representative records.
  2. Choose TypeScript, Go, or Python and generate the types.
  3. Include a record with a missing field and another with null to inspect optionality and nullability. Review empty arrays, mixed types, and generated names before integrating the declarations.

Details and limitations

  • Arrays of objects are treated as multiple observations, so a key missing from one item becomes optional instead of being silently declared universal.
  • TypeScript uses interfaces and unions, Go uses structs with JSON tags and falls back to any for mixed types, and Python uses TypedDict with NotRequired fields.
  • Empty arrays cannot reveal their element type, and the generated output says so rather than inventing a plausible element model.

WORKED EXAMPLES

A missing property is not a null value

Generate TypeScript from two observations of the same record shape. Only one observation contains nickname, so declaring it universally present would overstate the evidence.

Samples

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

Expected result

The inferred item has numeric id and optional string nickname. This sample does not establish that nickname may be null; add that observation or edit the type if the real contract allows it.

COMMON QUESTIONS

JSON to Types questions

Does one JSON sample prove the complete API contract?
No. The output describes the values that were observed. An unseen nullable field, a new enum value, or a field absent from every sample cannot be inferred, so the generated model should be reviewed against the real API contract.
How does it decide whether a property is optional?
When the top-level value or a nested value contains an array of objects, properties are merged across those objects. A property absent from at least one observed object is emitted as optional.