JSON to Go Struct Generator
Generate idiomatic Go structs from JSON payloads locally in your browser with PascalCase initialisms, json tags, omitempty toggles, and time.Time detection.
How to Use
- Paste a JSON payload or click Sample in the JSON to Go Struct Generator above.
- Enter your desired root struct name and toggle Inline structs, json tags, or omitempty as needed.
- Copy the aligned Go structs or click Download .go to save a models.go file directly.
What is JSON to Go Struct Generator?
A JSON to Go Struct Generator translates JSON objects and arrays into strongly typed Go struct declarations ready for encoding/json unmarshaling. It eliminates tedious manual struct scaffolding by inferring field types, normalizing snake_case or camelCase keys to exported Go identifiers, and emitting properly aligned struct tags.
How It Works
The generator parses your JSON string with JSON.parse(), merges fields across array elements to detect optional keys and mixed integer/float types, and maps values to int64, float64, bool, string, time.Time, slices, or any. It applies standard Go initialism rules (ID, HTTP, JSON, URL) and formats fields with gofmt-aligned columns and struct tags.
Common Use Cases
- Unmarshaling third-party REST webhooks — turn sample JSON payloads into ready-to-compile Go models
- Generating microservice DTOs — choose between top-level named structs or compact inline struct definitions
- Handling optional API keys — toggle json:"...,omitempty" tags and automatic pointer types for nullable values
- Inspecting private production payloads — generate Go structs safely offline without sending JSON to external sites
Technical Details
Pure client-side Go type inference engine (generateGoStructs) in src/tools/json-to-go.tsx. Supports 39 Go initialisms, int64/float64 promotion, RFC-3339 time.Time detection with conditional import "time", *T pointer promotion for nulls, gofmt-style column alignment, and safe tag escaping.
FAQ
Does the Go generator follow Go initialism conventions?
Yes. Common Go initialisms such as ID, URL, URI, HTTP, HTTPS, JSON, API, UUID, and SQL are automatically formatted in uppercase (for example, user_id becomes UserID and api_url becomes APIURL).
What is the difference between flattened and inline structs?
Flattened mode extracts nested objects into named top-level type declarations for clean reuse, while Inline mode embeds nested struct definitions directly inside parent struct fields.
How are numeric, timestamp, and nullable fields mapped?
Integers map to int64, floating-point values (or mixed int/float arrays) promote to float64, ISO-8601 timestamps map to time.Time with an automatic import, and nullable fields become pointer types such as *string.