T
THINKFORU
Submit Feedback

JSON to Go Struct Converter: Online Go Generator

JSON to Go Struct Converter: Online Go Generator

JSON to Go Struct Converter

Save on Google
// Go structs appear here
Related Developer Tools
Tool NameExplanation
JSON to TypeScript InterfaceGenerates typed TypeScript interfaces from any JSON payload.
HTML to JSX ConverterConverts HTML markup into valid React JSX (className, self-closing tags, style objects).
TOML to JSON ConverterTransforms TOML config files into clean, formatted JSON.
Binary to Text ConverterDecodes binary (0s and 1s) into readable text and back.
Base64 Encode / DecodeEncodes text or files to Base64 and decodes Base64 strings instantly.

JSON to Go Data Type Mapping Matrix

JSON Data RepresentationInferred Go TypeGolang PackageAllocation / Usage Note
42intbuiltinPlatform-sized (32/64-bit); fine for counts
-7intbuiltinSigned; negative values are valid
2147483647int32builtinFixed 32-bit; overflow errors on Unmarshal
9007199254740993int64builtinAbove 2^53; use for IDs and counters
1700000000 (Unix seconds)int64builtin, timeConvert with time.Unix(v,0)
1700000000000 (Unix ms)int64builtin, timeConvert with time.UnixMilli(v)
255uint8builtinByte-sized unsigned; rejects negatives
65535uint16builtinPorts, small enums
4294967295uint32builtinUnsigned 32-bit
18446744073709551615uint64builtinExact in Go, lossy in JavaScript
3.14float64builtinDefault Go type for JSON decimals
1.5float32builtinHalf the memory, lower precision
1e9float64builtinExponent notation decodes as float
0intbuiltinZero value; dropped by omitempty
19.99 (money)int64 (cents)builtinAvoid float for currency; store minor units
12345678901234567890123*big.Intmath/bigArbitrary precision; implements TextUnmarshaler
Number kept as textjson.Numberencoding/jsonUse with dec.UseNumber()
trueboolbuiltinZero value is false
falseboolbuiltinCannot tell false from missing; use *bool
"text"stringbuiltinUTF-8; invalid bytes become U+FFFD
""stringbuiltinEmpty string is the zero value
"2026-10-26T20:25:00Z"time.TimetimeRFC3339 parsed automatically
"2026-10-26T20:25:00+05:30"time.TimetimeOffset preserved in Location
"2026-10-26"stringbuiltin, timeDate-only fails time.Time; parse with layout 2006-01-02
"20:25:00"stringbuiltinTime of day; no stdlib type
"1h30m"time.DurationtimeNeeds custom UnmarshalJSON
"550e8400-e29b-41d4-a716-446655440000"uuid.UUIDgithub.com/google/uuidOr plain string without dependency
"dev@example.com"stringbuiltin, net/mailValidate with mail.ParseAddress
"https://example.com"stringbuiltin, net/urlParse later with url.Parse
"192.168.1.1"net.IPnetImplements TextUnmarshaler
"SGVsbG8="[]bytebuiltinStandard base64 decoded automatically
"#ff0000"stringbuiltinNo native color type
nullinterface{} / anybuiltinType unknown; assert at runtime
null in string field*stringbuiltinnil means null or absent
null in number field*intbuiltinSeparates 0 from null
null in boolean field*boolbuiltinTri-state: true, false, nil
null in object field*AddressbuiltinPointer to sub-struct
Optional string*string + omitemptybuiltinOmitted when nil, kept when empty
Optional int (0 is valid)*int + omitemptybuiltinPointer to 0 is still emitted
Optional decimal*float64builtinnil when absent
Optional boolean*boolbuiltinNeeded for PATCH payloads
Optional nested object*Profilebuiltinnil avoids empty-object output
Optional timestamp*time.TimetimePair with omitempty or omitzero
{}struct{}builtinZero-size; or map[string]any
{"a":1,"b":2} fixed keysstructbuiltinFastest; keys known at compile time
{"a":1,"b":2} dynamic keysmap[string]intbuiltinKey order not preserved
{"k":"v"}map[string]stringbuiltinHeaders, labels, env vars
Mixed-value objectmap[string]interface{}builtinNumbers decode as float64
{"a":{"x":1}}map[string]map[string]intbuiltinNested maps allocate per level
Nested objectNamed structbuiltinReusable and testable
Single-use nested objectAnonymous struct{...}builtinInline; cannot be reused
Deferred or polymorphic objectjson.RawMessageencoding/jsonZero-copy until decoded again
[][]interface{}builtinElement type unknown
["a","b"][]stringbuiltinGrows dynamically
[1,2,3][]intbuiltinUse []int64 for large IDs
[1.5,2][]float64builtinMixed int and float widen to float64
[true,false][]boolbuiltinFlags
[{...},{...}][]ItembuiltinContiguous memory; copies on append
[{...},{...}] (large)[]*ItembuiltinShared or mutated elements
[[1,2],[3]][][]intbuiltinJagged matrix
[1,"a",null][]interface{}builtinType-switch each element
[1,"a"] tuple[]json.RawMessageencoding/jsonDecode each index separately
[10.5,20.1] fixed length[2]float64builtinArray; extra items are dropped
["a","b"] unique setmap[string]struct{}builtinNeeds custom UnmarshalJSON
"active" enumtype Status stringbuiltinAdd consts and a validating Unmarshal
"123" quoted numberint64 + ,stringencoding/jsonCommon in JS-safe APIs
"true" quoted boolbool + ,stringencoding/jsonTag option handles quoting
Key "$ref"Ref stringbuiltinTag json:"$ref" maps odd keys
Key "user-name"UserName stringbuiltinTag required for dashes
String or number valueCustom typeencoding/jsonImplement UnmarshalJSON

Golang Struct Tag Configuration Matrix

Struct Tag FormatBehavior During json.MarshalBehavior During json.UnmarshalBest-Practice Scenario
json:"name"Writes key nameMatches key name, case-insensitiveDefault API field mapping
json:"name,omitempty"Skips false, 0, nil, "", empty slice or mapNo effectOptional fields in responses
json:"-"Field never writtenField never readPasswords, tokens, internal state
json:"-,"Writes key literally named -Reads key -Rare; API with a dash key
json:",omitempty"Uses Go field name, skips emptyMatches Go field nameKeep names, drop empties
json:"id,string"Writes number as quoted stringAccepts quoted number onlyint64 IDs consumed by JavaScript
json:"id,omitempty,string"Quoted, and skipped when 0Accepts quoted numberOptional stringified IDs
json:"at,omitzero"Skips zero value, including time.Time{} (Go 1.24+)No effectTimestamps and structs
json:"user_id" db:"user_id"Same as plain json tagSame as plain json tagsqlx row scanning plus JSON
json:"x" validate:"required"No effectNo effect; validate after decodingRequest validation
No tag, exported fieldKey equals Go field nameCase-insensitive matchQuick prototypes only
Unexported fieldIgnoredIgnoredPrivate state, cannot be tagged
Embedded struct, no tagFields promoted to parentFields promoted to parentShared base fields
*T with omitemptySkips nil only; pointer to 0 is writtenAllocates when key presentPATCH and nullable columns

Technical Q&A / FAQ Matrix

Technical Developer QuestionExact Go Idiomatic Solution & Code Snippet
How do I handle dynamic JSON keys?Decode into a map: var m map[string]Item; err := json.Unmarshal(b, &m). Use map[string]any if values vary.
How do I tell 0 apart from a missing field?Use a pointer: Age *int `json:"age,omitempty"`, then if u.Age == nil { /* absent */ }.
How do I parse a mixed-type array?Use []json.RawMessage and decode per index, or []any with switch v := x.(type).
How do I write custom unmarshaling?Implement func (t *T) UnmarshalJSON(b []byte) error. Use an alias type alias T inside to avoid infinite recursion.
How do I stop large int64 losing precision?Use dec := json.NewDecoder(r); dec.UseNumber() for any targets, or declare the field int64.
How do I reject unknown fields?dec := json.NewDecoder(r); dec.DisallowUnknownFields(); err := dec.Decode(&v).
How do I accept a value that is string or number?Define type Flex string and in UnmarshalJSON trim quotes when b[0] == '"', else use string(b).
How do I parse a non-RFC3339 date?Create type Date struct{ time.Time } and parse inside UnmarshalJSON with time.Parse("2006-01-02", s).
How do I keep unknown fields while using a struct?Decode twice: once into the struct, once into map[string]json.RawMessage, then delete known keys.
How do I pretty-print the output?out, _ := json.MarshalIndent(v, "", " ").