Skip to content
wonderstacked

JSON to Types Converter

Generate TypeScript, Go, Python and more from a JSON sample.

Runs in your browser
Loading JSON to Types Converter…

How do I generate TypeScript types from JSON?

A JSON to TypeScript converter infers types from a sample of JSON. This JSON to TypeScript converter also generates Zod schemas, JSON Schema, Go structs, Python dataclasses, Rust, Java and C#, merging arrays so missing keys become optional fields.

Writing types for an API response by hand is slow and easy to get wrong. Paste a sample response and the tool infers the structure: strings, numbers, booleans, nested objects and arrays, then emits declarations in the language you pick.

When an array holds several objects, they are merged into one type, and a key that appears in only some of them becomes optional. Output targets are TypeScript interfaces, Zod schemas, JSON Schema, Go structs, Python dataclasses, Rust, Java and C#.

The types describe the sample you gave, not the full contract: a field that is always a number in your sample may be null in other responses. Use several representative samples or edit the result. Conversion runs in your browser.

Page updated .

How to use the JSON to Types Converter

  1. Paste a JSON sample, ideally one with several array items.
  2. Choose the output language and options.
  3. Copy the generated types into your project.

Examples

Simple object
Input
{"id":1,"name":"Ada"}
Output
interface Root with id: number and name: string
Merged array
Input
[{"a":1},{"a":2,"b":"x"}]
Output
a: number and an optional b?: string

Tips

  • Paste a response that includes optional fields so they are detected.
  • Merge several samples into one array so edge cases appear.
  • Rename the root type to something meaningful.

Specs & limits

Targets
TypeScript, Zod, JSON Schema, Go, Python, Rust, Java, C#
Inference
Structural, with array merging
Optional fields
From keys missing in some items
Input
JSON sample
Processing
In your browser

Troubleshooting

›Everything is any or unknown

Cause: The sample is empty or an empty array.

Fix: Provide a sample with data.

›Wrong number type

Cause: An integer in the sample is a float elsewhere.

Fix: Edit the type or add more samples.

›Parse error

Cause: Invalid JSON.

Fix: Fix it with the JSON Formatter first.

Frequently asked questions

›How are optional fields detected?

If a key is missing from some objects in an array, it becomes optional in the merged type.

›What about null values?

A null in the sample is typed as null, so widen the type by hand if the field can also hold a value.

›Which languages are supported?

TypeScript, Zod, JSON Schema, Go, Python dataclasses, Rust, Java and C#.

›Are mixed-type arrays supported?

Yes, as union types where the language allows them.

›Is my JSON uploaded?

No. The inference runs in your browser.

›Why does the type not match my API?

The sample is only one example. Include several to cover variations.

More developer tools

See all
esc