JSON to Go Struct Converter
This JSON to Go converter turns a sample payload into struct declarations. Go requires exported — capitalised — field names for unmarshalling, while JSON keys are usually lowercase, snake_case or hyphenated, so every field carries a json tag with its original key to bridge the two. Fields absent from some records get omitempty so they are dropped on the way back out instead of being written as zero values. Whole numbers become int64 and decimals float64; a field that held both becomes float64, the type that can carry either.
How it works
Paste a representative JSON sample and the Go declarations appear on the right. The types are inferred from what is actually in the sample, so the more complete your example, the better the result — one array element with an extra field is enough to have that field marked optional rather than missed.
Each object becomes a struct with exported field names and a json tag carrying the original key, so unmarshalling round-trips even when the wire format uses snake_case or hyphens.
Fields that are absent from some records get omitempty, whole numbers become int64 and decimals become float64.
Generation runs entirely in your browser — nothing you paste is uploaded.
How to convert JSON to Go structs
- Paste a representative JSON payload into the input on the left.
- Set the package name if it is not
main. - Copy the generated structs into your project.
Struct tags do the real work
Go field names must be exported to be unmarshalled, which means capitalised — but JSON keys are usually
lowercase, snake_case or hyphenated. Every field therefore carries a json:"…" tag with the original
key, so encoding/json maps the two correctly. Fields absent from some records get
omitempty so they are dropped on the way back out rather than written as zero values.
Number types
Whole numbers become int64 and decimals become float64. If a field held both in your
sample it becomes float64, since that is the type that can carry either.
Give it a representative sample
The types are inferred from the data you paste, so the quality of the output depends on how complete your example is. Two things are worth including: an array with more than one element, so fields that appear in some records but not others get marked optional rather than assumed mandatory; and real values rather than placeholders, so numbers are recognised as numbers and whole numbers are told apart from decimals.
What inference cannot tell you
A sample shows what the data was, not what it can be. A field that happened to be null in every record you pasted has no discoverable type, and an enum looks exactly like a string. Treat the generated structs as a first draft that saves the typing, then tighten the parts you know more about than the sample does.
Frequently asked questions
Why does every field need a json tag?
Go only unmarshals into exported fields, which must start with a capital letter, but JSON keys are typically lowercase or snake_case. The tag tells encoding/json which key maps to which field, so both sides keep their own conventions.
When is omitempty added?
To fields that were missing from some records in the sample. Without it, an absent value would be marshalled back out as a zero value — an empty string or a 0 — which is a different statement from "not present".
Which number types are used?
Whole numbers become int64 and decimals become float64. A field that held both in the sample becomes float64, since that is the type that can represent either.
Can I set the package name?
Yes. A dotted namespace contributes only its last segment, because a Go package name is a single lowercase identifier and cannot contain dots.
Is my JSON sent to a server?
No. Everything is generated locally in your browser.
Related tools
JSON to TypeScript Converter
This JSON to TypeScript converter turns a sample payload into exported interfaces.
JSON to Java Class Converter
This JSON to Java converter generates POJOs with Jackson annotations, getters and setters.
JSON to JSON Schema Generator
This JSON to JSON Schema generator produces a draft 2020-12 schema from a sample payload.