JSON to Go Struct Generator
Convert JSON to idiomatic Go structs with json tags, time.Time detection, omitempty support. Free, in-browser.
What this does
Converts a JSON document into a Go struct definition with proper json:"..." struct tags. The generator follows Go idioms:
- PascalCase field names —
user_idbecomesUserID(with the recognized acronym uppercased), notUserId. Common acronyms (ID,URL,API,HTTP,JSON,UUID,SSL,IP,DNS) are kept all-caps as Go’sgofmt/golintexpects. - Tab-aligned columns — field name, type, and tag align like a vet-clean struct.
- Nested structs are inlined as separate type declarations, named after the parent key (singularized for arrays of objects).
- Numeric inference — integer values become
int, decimal values becomefloat64. Mixed arrays widen tointerface{}/any. time.Timedetection — ISO 8601 timestamps (2026-06-05T12:00:00Z) becometime.Timewith the right import added.omitemptytoggle — on by default. Off when you want zero-values to round-trip.anyvsinterface{}toggle —anyis Go 1.18+. Toggle tointerface{}for older codebases.
What “good Go” looks like (and what this avoids)
A common mistake junior generators make is producing structs like:
type Root struct {
Id int `json:"id"`
UserId int `json:"user_id"`
UserUrl string `json:"user_url"`
}
Notice Id, UserId, UserUrl — these names lose at golint. Real Go style is ID, UserID, UserURL. This generator handles that automatically. If your JSON happens to spell out id lowercase but the team standard for the corresponding Go field is ID, the output is already correct — no manual rename pass.
When type inference is good enough
A single JSON sample tells the generator about that sample. It can’t tell you:
- That a
nullfield is sometimes a string (useomitempty, then changestringto*string). - That an integer-looking field can occasionally exceed
int32— switch toint64if the API can return values > 2 billion. - That an array’s element type isn’t always uniform — when it isn’t, the generator widens to
interface{}rather than guess wrong. - That a field is sometimes absent. The presence of
omitemptydoesn’t change unmarshalling — it only affects how zero-values encode back out.
Generate, then hand-tune. This is faster than starting from scratch and more conservative than trusting the output verbatim.
Common use cases
- API client typing. Hit your endpoint with curl or HTTPie, paste the response, get the struct to start typing your client.
- Microservice contracts. Internal services often have JSON-over-HTTP contracts that aren’t formally documented. A real response sample → real struct → committed to the repo.
- Migrating from
map[string]interface{}. If your existing Go code parses JSON into a generic map and accesses fields withm["foo"].(string), paste a real response and replace the map with a struct for type safety. - Database schema bootstrapping. Round-trip JSON → struct → struct tags →
sqlboiler/gorp/ etc. The struct definition is your starting point.
Privacy
The tool runs entirely in your browser. JSON never leaves your machine.