Add meaningful variants
Combine records from the same response shape in an array. Unrelated objects in different fields receive separate nested types, even when their structures look alike.
Type generation
Compare the two records and their generated fields. The result includes a package declaration and only the imports it needs.
Parsed and generated in this browser. Input is not uploaded or stored.
3 declarations · 2 pointer types
JSON to Go turns representative API responses into an initial Go model. Include several records in one array to expose fields that may disappear, become null or change type.
Treat the result as a reviewable draft. Sample inference cannot discover required fields, business validation or values that your examples never contain.
JSON to Go examines all elements at the same array position. A field present only in the second record still appears in the model; concrete values paired with null or a missing property can produce pointers.
Integer tokens within int64 range use int64. Decimal, exponent and larger tokens use json.Number, so the generator never rounds an amount through JavaScript floating point before choosing its type.
Combine records from the same response shape in an array. Unrelated objects in different fields receive separate nested types, even when their structures look alike.
Disable date inference when a timestamp must remain a string. Disable named nested types for inline structs. Turning off JSON tags also removes the original-key mapping; review that choice before decoding.
Automatic generation waits 350 ms. Switch it off to show Generate, or use Ctrl/Cmd+Enter. Changes immediately disable copy and download until the current input succeeds.
This Go struct generator converts snake_case and camelCase to exported names, retaining common initialisms such as ID. Collisions receive stable numeric suffixes. Enabled json tags keep the original key spelling.
Nullable fields with a known scalar or struct type use pointers by default. Slices and maps already support nil. A null-only field becomes any; missing and explicit null both decode to nil, so pointers do not provide three-state tracking.
Only plain integer tokens in the signed 64-bit range become int64. Even 1.0 and 1e3 use json.Number, because encoding/json does not decode those spellings directly into integers. Review Number conversion methods before performing arithmetic.
Complete, valid RFC3339 strings with up to nine fractional digits may become time.Time. All samples at that position must qualify. Named or inline structs are available, and root scalar aliases retain the original package type methods.
A known scalar or struct field gets a pointer when a sample omits it or supplies null, if the option is enabled. Nil and a concrete zero are distinguishable; absence and explicit null are not. Turning pointers off uses zero-value semantics.
Plain integer tokens within int64 range use int64. Other numeric spellings use json.Number. In mixed any positions, configure Decoder.UseNumber() separately to avoid default float64 decoding.
Yes, when all non-null strings at that position are valid complete RFC3339 timestamps with at most nine fractional digits. Otherwise they stay string. The switch lets you keep date text even when it qualifies.
Names become exported ASCII identifiers with stable collision suffixes. Tags preserve supported original keys; unsupported keys cause a path error. Without tags, encoding/json matches exported names and the mapping may change.
Yes. JSON to Go defaults to named nested types derived from the root and containing field. Turn the nested-type option off to embed anonymous structs. Objects at unrelated positions remain independent.
Found an inference case to improve?
Use JSON to Go with several realistic records, check pointers, numeric types and timestamp choices, then export the file for testing in your project.