Skip to content

Convert JSON to TypeScript, Go, Python and more

Paste JSON samples and get TypeScript interfaces, Zod schemas, Go structs, Python, Java, C#, Kotlin, Swift and Rust types, generated in your browser.

Several samples (one after another, or JSON Lines) and the objects inside arrays are merged: keys missing somewhere become optional, null values nullable.

TypeScript
Paste a sample and press Generate types.
Declare as
Runs in your browser · no uploadHow it works

How to use JSON to types

  1. 1

    Paste JSON samples

    Paste one response, an array of records, or several responses one after another; Sample shows two merged users.

  2. 2

    Pick the language

    Choose TypeScript, Zod, Go, Python, Java, C#, Kotlin, Swift or Rust, and the style options for it.

  3. 3

    Name the root type

    Set the name of the top-level type, for example User or OrderResponse.

  4. 4

    Generate and copy

    Press Generate types, then copy the code or download it; edits regenerate it automatically.

Limits and Pro

Free with no sign-up: 9 output languages with 3 Python styles, any number of merged samples and files up to 20 MB, with generation stopped after 30 seconds.

Pro removes the ads; the generator is the same on every plan. See Pro

About JSON to types

Writing types by hand for an API response is slow and error-prone, especially when the payload is nested three levels deep. Paste one or more JSON samples and this generator infers the structure and writes ready-to-paste definitions in nine flavours: TypeScript interfaces or type aliases, TypeScript with Zod schemas for runtime validation, Go structs with json tags, Python dataclasses, TypedDicts or Pydantic v2 models, Java records with Jackson annotations, C# classes for System.Text.Json, Kotlin data classes for kotlinx.serialization, Swift Codable structs and Rust structs for serde.

One sample rarely shows every field, so the generator merges as many as you give it. Paste several documents one after another or as JSON Lines, or an array of objects: a key that is missing from some objects becomes optional, a key that is sometimes null becomes nullable, an integer that is sometimes a decimal becomes a float, and genuinely mixed values become a union or the language's dynamic JSON type. Nested objects get their own named types — orders becomes Order, addresses becomes Address — and identical shapes are generated once and reused. Objects whose keys are numbers, UUIDs or dates are turned into maps.

Field names are converted to each language's convention, and JSON keys that differ, such as first-name or class, are mapped back with the right annotation, alias or CodingKeys. Comments and trailing commas in the sample are tolerated.

The output describes the samples you provide; the generator can't know about fields or values your samples don't contain, so review it against your API documentation before relying on it.

Privacy

Samples are parsed and the code is generated by a Web Worker in this tab, so API responses containing personal or internal data are never uploaded. The language and naming options are saved in local storage; the JSON you paste is not kept.

Features

Merges many samples

Missing keys become optional and null values nullable across all the samples you paste.

9 languages

TypeScript, Zod, Go, Python, Java, C#, Kotlin, Swift and Rust with idiomatic naming.

Key mapping included

json tags, aliases, @SerialName, @JsonProperty and CodingKeys keep the original JSON names.

JSON to types: frequently asked questions

How does it decide which fields are optional?
A field is optional when at least one of the objects at that position doesn't contain the key. If you paste a single object, every field is required, because nothing shows otherwise. Paste several real responses, or an array of records, to let the generator see which keys come and go. Make every field optional is there for partial or patch payloads.
What happens when a value is sometimes null?
The field becomes nullable: string | null in TypeScript, a pointer in Go, str | None in Python, String? in Kotlin and Swift, Option<String> in Rust and a boxed or nullable type in Java and C#. A field that is null in every sample has no type to infer, so it becomes the language's unknown or dynamic JSON type.
Why did my integers become floats?
If one sample has 7 and another has 7.5 for the same field, the type must hold both, so it becomes a float or double. Numbers written with a decimal point, such as 10.0, also count as decimals. In TypeScript both are number; with Zod an integer-only field is checked with z.number().int().
Is this the same as quicktype?
It solves the same problem with its own generator, which runs entirely in your browser and adds a few things: three Python styles including TypedDict, Zod schemas, and merging of several pasted documents. quicktype supports more languages and can read JSON Schema. For the nine languages here the output is designed to compile without extra runtime helpers.
Can it detect dates, enums or UUIDs?
No. Strings stay strings, because a handful of samples can't prove that every future value will be a date or one of a fixed set. Change the generated type by hand to Date, time.Time, datetime, an enum or a UUID type where your API guarantees it. Objects keyed by UUIDs, numbers or dates are the exception: they become maps.
All developer tools