Type generation

JSON to Gomodels for the values you actually received

Compare the two records and their generated fields. The result includes a package declaration and only the imports it needs.

JSON to Go

JSON input

Parsed and generated in this browser. Input is not uploaded or stored.

Go result

Generation options

Tags preserve supported keys. any requires Decoder.UseNumber() for exact numbers; pointers do not distinguish absent from null.

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.

Why use JSON to Go?

Consider every record

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.

Two record cards with different fields converge into one complete structure, with hollow pointer markers for missing values.

Keep numeric evidence intact

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.

A long sequence of numeric blocks enters a matching sequence in a structured output card without losing blocks.

Inspect the model before using it

01

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.

02

Choose what the sample can justify

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.

03

Refresh the current configuration

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.

Names, nulls and numeric types

Exported names with original keys

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.

Pointers where evidence supports them

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.

Numbers without an early rounding step

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.

Time and nested declarations

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.

Compatibility and inference boundaries

Go 1.18+ compatible source
The JSON to Go struct output uses any and the encoding/json v1-compatible tag subset. It emits no custom UnmarshalJSON, validation, omitempty, Schema conversion or runnable application. Run gofmt and tests in your own project.
Some keys need a different model
With tags enabled, empty keys, commas, quotes, backslashes, backticks, controls and emoji fail with a path. Use map[string]any or a custom decoder for such keys. The key - is supported using the tag -, to avoid ignoring its field.
Unknown values need decoder care
Mixed types become any, empty arrays []any and empty objects map[string]any. Use Decoder.UseNumber() when decoding numbers into these generic positions; the default decoder otherwise uses float64. Samples do not define the full API contract.
Time is not a verbatim string
Invalid dates, date-only strings, missing zones and more than nine fractional digits remain string. time.Time may normalize offsets and fractional zeros when encoded again. Turn inference off when exact timestamp text matters.
Strict input and finite budgets
Comments, duplicate keys, trailing commas and multiple documents are rejected. There is no URL fetch, file import or repair. Limits: 500,000 input characters, depth 100, 50,000 nodes, 1,000 declarations and 1,000,000 output characters.

JSON to Go questions

Why does the output use pointer fields?

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.

Which Go types are chosen for numbers?

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.

Can timestamps become time.Time fields?

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.

How are exported names and JSON tags generated?

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.

Can nested objects use named or inline structs?

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?

Review a representative response

Use JSON to Go with several realistic records, check pointers, numeric types and timestamp choices, then export the file for testing in your project.