Turn JSON into typed models

Generate classes, records and structs from a sample payload. Pick a language and the root name.

7 languages0 bytes uploaded

Language

Input

Waiting for input

Result

Result appears here

What each language gets

LanguageOutputOptions
Javarecord or POJOJackson or Gson annotations, Lombok @Data, @Getter/@Setter and @Builder, ignore unknown fields, package
Kotlindata classkotlinx.serialization, Moshi, Gson or Jackson; val or var; package
TypeScriptinterface, type alias or Zod schemaexport, readonly
PythonPydantic model, dataclass or TypedDict3.10+ syntax (list[str], int | None) or typing.List/Optional
Gostruct with json tagspointers for optional fields, omitempty, any or interface{}, package
C#class or recordSystem.Text.Json or Newtonsoft.Json attributes, nullable reference types, namespace
Ruststruct with serde derivesDebug, Clone, PartialEq; rename_all = "camelCase"; skip None

Options stay as you set them while you switch languages, and the result updates as you change them.

How types are inferred

Numbers
Whole numbers become int (long above 2,147,483,647). Any number with decimals becomes double, and an array that mixes both, like [1, 2.5], becomes a list of doubles.
Arrays of objects
Every item is merged into one type, so the class gets the union of all the keys it sees.
Missing keys
A key that appears in some items and not in others is optional: note?: string in TypeScript, a nullable or Option type elsewhere.
null
A null in some items makes the field nullable. A key that is null everywhere carries no type at all, so it becomes Object, unknown, Any or serde_json::Value.
Mixed types
If the same key holds a string in one item and a number in another, the field falls back to that same catch-all type.
Nested objects
Each one becomes its own class, named after its key in PascalCase. Keys of arrays are made singular: orders gives Order, categories gives Category. Two classes with the same name get a number (Address2).
Dates
Stay strings. The converter does not guess formats; change the type yourself if you want Instant, LocalDate or datetime.

Field names and annotations

JSON keys are often not valid names in your language: full-name, 2fa, class. The converter writes the idiomatic name for each language (camelCase for Java and Kotlin, snake_case for Python and Rust, PascalCase for Go and C#) and maps it back to the original key with the annotation your library expects. Reserved words get an underscore, so class becomes class_.

Java with Jackson
public record User(
    @JsonProperty("full-name") String fullName,
    @JsonProperty("class") String class_
) {}
Go
type User struct {
	FullName string `json:"full-name"`
	Class    string `json:"class"`
}

TypeScript keeps the original keys and quotes them where needed ("full-name": string), because the type has to match the object that JSON.parse returns.

Getting a good result from your sample

The converter only knows what your sample shows. A few minutes spent on the sample saves more time than fixing the classes afterwards:

  • Use a real response, not one typed from memory. Copy it from your browser's network tab or from curl.
  • Show the variation. Put two or three items in each array, including one with the optional fields, so the converter can tell what is optional.
  • Replace nulls you can type. If you know deletedAt is a date string when present, give it a value in the sample.
  • Write decimals as decimals. A price of 10 is typed as an integer; 10.5 is typed as a double.
  • Trim long arrays. Three items teach the converter as much as three thousand.
  • Review before you commit. Money usually wants BigDecimal or Decimal, IDs may want strings, and string fields with a fixed set of values may want an enum.

Language guides

For the decisions the converter cannot make for you, read JSON to Java: records, POJOs, Jackson and Gson and JSON to TypeScript: interfaces, types and Zod.

If the converter says your input is invalid, paste it into the formatter: its status line points at the problem.

Load JSON from a URL

The server must allow cross-origin requests (CORS).