Convert JSON into Go struct definitions with encoding/json tags. Field names follow Go's exported-name rule and golint's initialism list (ID, URL, API, ...), and columns are aligned as if the code had been through gofmt.
It is useful when you need a type to json.Unmarshal a webhook payload or API response into, a request-body struct for net/http, Gin or Echo handlers, or a config struct for a CLI.
omitempty.Struct name (default Root); it stays in the URL as ?name=..go file and add a package clause. If time fields were found, import "time" is included.var ev WebhookEvent; err := json.Unmarshal(body, &ev).{
"event_id": "evt_1Pq",
"type": "invoice.paid",
"created_at": "2024-05-01T03:15:00Z",
"amount_cents": 4999,
"customer": { "id": "cus_9", "email": "kim@example.com" },
"retry_count": null
}import "time"
type WebhookEvent struct {
EventID string `json:"event_id"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
AmountCents int `json:"amount_cents"`
Customer Customer `json:"customer"`
RetryCount any `json:"retry_count,omitempty"`
}
type Customer struct {
ID string `json:"id"`
Email string `json:"email"`
}
event_id becomes EventID under golint's initialism rule, and created_at, an RFC 3339 string, is inferred as time.Time, which adds import "time". retry_count is null, so its type is unknown: it becomes any with omitempty.
json:"originalKey" tag on every field, plus ,omitempty for fields missing from some rows or containing null.int, string, bool, structs, time.Time) become pointers (*int) so "absent" differs from the zero value. Slices and any are already nilable and stay non-pointer.int for 32-bit integers, int64 beyond that, float64 when decimals appear.2024-05-01T03:15:00Z are inferred as time.Time.user_id → UserID, home_url → HomeURL); keys starting with a digit get a Field prefix."", are skipped and listed in a comment above the struct.[]Root.Build a struct from a sample event sent by a payment or Git hosting service and decode it with json.NewDecoder(r.Body).Decode(&ev), instead of repeated type assertions on map[string]any.
Generate the struct for c.ShouldBindJSON(&req) from a client request sample, then add binding:"required" tags where needed.
Turn config.json into a struct once, and a single json.Unmarshal after os.ReadFile gives you the whole config as typed values.
time.Time is only inferred for RFC 3339 strings; values like 2024-05-01 03:15:00 or Unix timestamps stay string or int.json.Unmarshal ignores unknown keys and matches keys case-insensitively by default. Use Decoder.DisallowUnknownFields() if you want strict decoding.int is 64-bit on 64-bit platforms, but int64 is written only when a sample value exceeds 32 bits. For IDs that can grow, switching to int64 yourself is safer.null become any; replace them once the real type is known.*int?A plain int field is 0 when the key is missing, indistinguishable from a real 0. A pointer is nil when the key is absent or null, and together with omitempty the key is left out when you marshal again.
encoding/json only reads and writes exported (capitalized) fields; lower-case fields are ignored even with a tag. In Go, names stay capitalized and the JSON key goes in the tag.
null field like retry_count came out as any.With only null in the sample there is nothing to infer a type from. Add another response with a real value to an array and convert both, or change it to something like *int by hand.
Yes. Paste the struct into the Go struct → JSON tab at the top; it reads the tags and produces example JSON.