JSON to Go Structs, Rust Serde & Python Models
Convert JSON to Go structs, Rust Serde structs or Python Pydantic models online. Correct types, json tags and serde attributes included. Free, no upload.
Paste JSON on the left and pick Go, Rust or Python to generate typed structs on the right. Go output carries `json:"field"` tags, Rust output carries Serde derive attributes and renames, and Python output is a Pydantic BaseModel with annotated fields.
The same JSON payload can be turned into idiomatic types for statically typed languages. JSON2X generates Go structs with json:"…" tags, Rust structs with Serde derives and rename attributes, and Python Pydantic models with annotated fields — each following the naming conventions of its own language rather than copying the JSON keys verbatim.
How are JSON keys mapped to language conventions?
Names are converted, and the original key is preserved in an attribute. A JSON key created_at becomes the exported Go field CreatedAt with the tag json:"created_at", the Rust field created_at under #[serde(rename = "created_at")] when needed, and the Python field created_at directly. This matters because Go only serialises exported (capitalised) fields, so a struct without tags silently produces CreatedAt in its output and fails to match the API.
How is nullability handled per language?
Each language expresses "maybe absent" differently, and getting it wrong is the usual source of runtime panics. Go has no optional type, so a nullable field needs a pointer (*string) to distinguish absent from empty — otherwise a missing string silently becomes "". Rust makes it explicit with Option<T>, and Serde will error on a missing field that is not optional. Pydantic uses str | None = None. The generator marks what it can see; anything the API can omit but your sample includes has to be widened by hand.
What about numbers and dates?
JSON has one numeric type, so inference guesses from the sample: a whole number becomes int64/i64/int and a fractional one becomes float64/f64/float. A field that is integral in your example but occasionally fractional in production will fail to deserialise, so widen it deliberately. Dates arrive as ISO 8601 strings with no type marker; Go can decode them into time.Time, Rust needs chrono with a Serde feature, and Pydantic will coerce a string into datetime automatically.
How to use the JSON to Code
Takes under a minute. Nothing is uploaded — every step runs in this browser tab.
- Paste JSON
Put an object or API response into the left-hand input pane.
- Pick a language
Choose Go, Rust, or Python. The naming convention, type names, and serialisation attributes change with the target.
- Read the generated types
The right-hand pane shows the root type plus one named type per nested object, ready to paste into a source file.
- Adjust nullability
Widen fields the API can omit — a Go pointer, a Rust `Option<T>`, or a Python `| None` — since one sample cannot prove a field is always present.
When to use it
- Unmarshalling a third-party API response in a Go service
- Deserialising a config or payload with Serde in a Rust binary
- Validating an incoming request body with Pydantic in a FastAPI route
- Porting a TypeScript client’s types to a backend in another language
- Generating fixtures types for integration tests against an external API
Searches this page answers
- json to go struct online
- free json to go converter
- json to rust serde struct
- json to python pydantic model
- json to golang converter
- generate struct from json
- json to dataclass online
Frequently Asked Questions
Which programming languages are supported in JSON to Code?
Go (struct with json tags), Rust (struct with serde derives and #[serde(rename)] attributes), and Python (Pydantic BaseModel).
How do I convert JSON to a Go struct?
Paste the JSON, choose Go Struct, and set the root name. Every key becomes an exported field with an inferred type and a `json:"original_key"` tag, so unmarshalling round-trips without renaming anything by hand.
Can it generate Python dataclasses instead of Pydantic models?
Not currently — Python output is a Pydantic BaseModel with typed fields and Optional where a value was null. Converting the class to a dataclass is a mechanical edit: swap the base class and the import.
Is this JSON to Go and Rust converter free, and is my JSON uploaded?
It is free with no signup, and nothing is uploaded. Struct generation runs in your browser, so internal API payloads stay on your machine.
Related Developer Tools
Last reviewed by the JSON2X Engineering Team.