Skip to content
induwara.lk
Premium
induwara.lkDeveloper · Utility

JSON to Code Generator — Go, Python, Java, Kotlin, C# & Rust

Paste a JSON sample and get typed data structures in the language you need — Go structs, Python dataclasses or Pydantic v2 models, Java records, Kotlin data classes, C# classes, or Rust structs. Nested objects, merged arrays, and optional or null fields are handled for you. Runs entirely in your browser; nothing is uploaded.

By Induwara AshinsanaUpdated Jul 16, 2026
JSON to Go
Runs in your browser
Target language

274 characters. Paste an API response, then pick a language above.

Status
Valid JSON
Parsed per RFC 8259
Types generated
3
3 Go types: Profile, Order, Root
Accepts input
Verified
Your JSON structurally satisfies the generated types.
Input size
274
characters parsed

Inferred types

Field pathJSON typeMapped typeFlags
user_idnumber (integer)int64
namestringstring
is_activebooleanbool
rolesarray[]string
profileobjectProfile
profile.citystringstring
profile.postal_codenumber (integer)int64
ordersarray[]Order
orders[].idstringstring
orders[].totalnumber (decimal)float64
orders[].paidboolean*bool
optional
orders[].notestring*string
optional

All parsing and code generation runs in your browser. Sources: Go, Python, Pydantic v2, Java (Jackson), Kotlin, C# (System.Text.Json), and Rust (serde) specifications — cited below the tool.

How it works

This is a deterministic source-to-source transformation, not a guess. The JSON is parsed once with JSON.parse following RFC 8259, which defines the six JSON value types — object, array, string, number, boolean, and null. A single recursive pass infers a language-neutral shape for every node, then a per-language emitter prints code using each language's own specification for types and serialization.

  1. Primitives. A JSON string maps to string/str/String, and a boolean to the language's bool type. Because JSON has only one number type, the tool checks the literal: a whole number becomes an integer type (int64, i64, long), a decimal becomes a floating type (float64, f64, double). The 64-bit toggle switches integers between 64- and 32-bit width.
  2. Objects become named types. Each object is emitted as a struct, record, data class, or class. The name is the PascalCased key — a profile object becomes Profile, and an orders array of objects yields a singularised Order element type. Structurally identical objects reuse one type; genuine name clashes get a numeric suffix.
  3. Arrays are merged.Every element is inferred and the schemas are unioned: object fields are merged, and a key present in only some elements is marked optional. A key seen as an integer in one element and a decimal in another widens to the floating type. An empty array has nothing to infer, so its element falls back to the language's any/Value type.
  4. Optional and nullable. A missing key is optional; a null value is nullable. Both render as the idiomatic optional form — a pointer with omitempty in Go, Optional[T] = None in Python, Option<T> in Rust, a boxed nullable in Java, and T? in Kotlin and C#.
  5. Naming and safety.Field names are cased to each language's convention (exported PascalCase for Go, snake_case for Python and Rust, camelCase for Java and Kotlin), while the original wire name is preserved in a json tag, @JsonProperty, serde rename, @SerialName, or [JsonPropertyName]. Keys that start with a digit or contain hyphens are sanitised (first-name first_name), and reserved words are escaped.

Because the rules are fixed, identical input and identical options always produce byte-identical output. As a cross-check, the generator runs a structural assignability test — it confirms your original JSON value satisfies the types it just produced — and shows the result as the Accepts input badge. Every mapping is traceable to the language and serializer specifications cited below.

Worked examples

Go struct — nested object + typed array

Go · 64-bit ints · tags on

Input JSON

{ "user_id": 42, "name": "Nimal",
  "is_active": true,
  "roles": ["admin", "editor"],
  "profile": { "city": "Colombo", "postal_code": 70000 } }

Generated code

type Profile struct {
	City       string `json:"city"`
	PostalCode int64  `json:"postal_code"`
}

type Root struct {
	UserID   int64    `json:"user_id"`
	Name     string   `json:"name"`
	IsActive bool     `json:"is_active"`
	Roles    []string `json:"roles"`
	Profile  Profile  `json:"profile"`
}
  1. 42 has no fractional part, so it maps to int64; roles is an array of strings → []string.
  2. profile is extracted into its own Profile struct and emitted before Root (children-first).
  3. user_id exports to UserID (the “id” initialism is upper-cased) with the wire name kept in the json tag.

Pydantic v2 — array merge + widening

Python (Pydantic v2) · tags on

Input JSON

{ "orders": [
    { "id": "ORD-1", "total": 4500.5, "paid": true },
    { "id": "ORD-2", "total": 300, "note": "gift" }
] }

Generated code

class Order(BaseModel):
    id: str
    total: float
    paid: Optional[bool] = None
    note: Optional[str] = None


class Root(BaseModel):
    orders: list[Order]
  1. The two order objects merge into one Order model. paid is missing from element 2 and note from element 1, so both become Optional.
  2. total is 4500.5 (decimal) in one element and 300 (whole) in the other, so the type widens to float.
  3. Fields with defaults are printed after those without, satisfying Python's default-ordering rule.

Rust — key sanitisation with serde

Rust · tags on

Input JSON

{ "first-name": "Amaya", "2fa": false }

Generated code

#[derive(Debug, Serialize, Deserialize)]
pub struct Root {
    #[serde(rename = "first-name")]
    pub first_name: String,
    #[serde(rename = "2fa")]
    pub two_fa: bool,
}
  1. first-name is not a valid Rust identifier, so it is snake-cased to first_name.
  2. 2fa starts with a digit, so the leading digit becomes a word → two_fa.
  3. Both keep the original wire name via #[serde(rename)], so the struct round-trips to the source JSON.

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a JSON shape that generates wrong code, or want another language target?

Email me at [email protected] — most fixes ship within 24 hours.