BackendBench
Coffee
Free tool

JSON to code

Paste a JSON sample and get typed models for Kotlin, C#, Go, Python, Rust or Swift, with renamed fields mapped back correctly.

Output

From a JSON sample to typed models

Every service that consumes a JSON API ends up with the same chore: read an example response and write the classes, structs or data classes for it, in whichever language the service uses. It is mechanical, easy to get subtly wrong (a field that is sometimes missing, a number that is sometimes a decimal) and not interesting. This converter does it for Kotlin, C#, Go, Python, Rust and Swift from a single pasted sample.

Nested objects become their own types, named after the key that holds them, with plural names singularised for list items (orders gives Order). Keys that are not valid identifiers, or that clash with language keywords (type in Rust, class in Kotlin), are renamed and mapped back with the right annotation: @SerialName, JsonPropertyName, a struct tag, a Pydantic alias, #[serde(rename)] or Swift CodingKeys.

Reading the result critically

For Java, use the JSON to Java converter on this site, which can also generate records and Lombok classes. Nothing you paste is uploaded.

Frequently asked questions

Which libraries do the generated models target?

Kotlin uses kotlinx.serialization, C# uses System.Text.Json, Go uses encoding/json struct tags, Python offers dataclasses or Pydantic v2, Rust uses serde and Swift uses Codable. Field renames are added where the JSON name differs from the idiomatic name.

How does it decide a field is optional?

A field that is null in the sample, or missing from some objects in an array, becomes nullable or optional (?, Option, omitempty, | None). One sample cannot prove a field is always present, so review the result.

What happens when an array mixes types?

Whole numbers and decimals merge to a floating-point type. Other mixtures, such as strings and numbers in one array, fall back to a generic JSON type (JsonElement, any, Any, serde_json::Value).

Can it also make a JSON Schema?

Yes. Use the JSON Schema generator on this site for draft 2020-12 schemas and OpenAPI components from the same sample.

More tools you might need