# JSON to Code

> Generate Go, Python, Java, C#, Rust, Zod, Kotlin, Swift and PHP types from JSON. Runs entirely in your browser, so nothing is uploaded.

Source: https://toffeekit.com/tools/json-to-code

**Category:** [Developer](https://toffeekit.com/category/developer) · **Price:** Free · **Runs:** in your browser, nothing is uploaded

Open the tool: https://toffeekit.com/tools/json-to-code

**Also useful for:** json to go, json to python, json to java, json to c#, json to rust, json to zod, json to kotlin, json to swift, json to php, json to pydantic, json schema, quicktype

## What you can do

- **JSON to Go structs** — Structs with json tags, omitempty and Go-style names. ([open with this preset](https://toffeekit.com/tools/json-to-code?preset=go))
- **JSON to Pydantic** — Pydantic models, dataclasses or TypedDicts with aliases. ([open with this preset](https://toffeekit.com/tools/json-to-code?preset=python))
- **JSON to Zod** — Zod schemas plus inferred TypeScript types. ([open with this preset](https://toffeekit.com/tools/json-to-code?preset=zod))
- **JSON to Rust** — serde structs with renames and Option fields. ([open with this preset](https://toffeekit.com/tools/json-to-code?preset=rust))

## How it works

1. Paste a JSON object or an array of objects, or click Open to load a .json file.
2. Choose a Language and type a Root type name.
3. Pick a Style for Python or Java, or a Serializer for C#, and toggle Make all optional if needed.
4. Copy or Save the generated code.

## FAQ

### How are optional fields detected?

When the JSON is an array of objects, a key missing from some items is marked optional. A key that is null in some items is marked nullable. Use Make all optional when your sample doesn't show every case.

### How are numbers typed?

Whole numbers become 64-bit integers (int64, long, i64, Long) and numbers with a decimal point become floats. If a field mixes both across items, it becomes a float.

### What happens to fields with mixed types?

They get the language's catch-all type: any in Go, Any in Python, Object in Java, serde_json::Value in Rust, JsonElement in Kotlin and z.unknown() in Zod. Swift gets a small JSONValue enum.

### Are nested objects separate types?

Yes. Each nested object becomes its own named type based on its key, and arrays use the singular form, so projects becomes Project. Objects with identical shapes share one type.

### How are JSON keys with dashes or snake_case handled?

Field names follow each language's style, and the original key is kept with json tags, @JsonProperty, @SerialName, serde rename, CodingKeys or a Pydantic alias.

### Is JSON to Code free and private?

Yes. It's free with no sign-up or limits, and it runs entirely in your browser, so what you type or paste never leaves your device. It works on phones and computers alike.

## Privacy

JSON to Code runs entirely in your browser. Your files and text are processed on your device and are never uploaded.

## Related tools

- [JSON Formatter](https://toffeekit.com/tools/json-formatter) — Format, minify and validate JSON with clear errors.
- [Base64 Encode / Decode](https://toffeekit.com/tools/base64-encoder) — Encode text to Base64 or decode it back, UTF-8 safe.
- [URL Encode / Decode](https://toffeekit.com/tools/url-encoder) — Percent-encode query values or whole URLs.
- [HTML Entities](https://toffeekit.com/tools/html-entity-encoder) — Escape < > & and quotes, or decode entities.
- [JWT Decoder](https://toffeekit.com/tools/jwt-decoder) — Read a token's header, claims and expiry.
- [Hash Generator](https://toffeekit.com/tools/hash-generator) — MD5, SHA-1, SHA-256, SHA-384 and SHA-512 at once.

