~/tools/-json-to-go-
Type generator - JSON to Go

$ Convert JSON to Go structs

Paste a JSON payload and get Go struct definitions with json tags, ready for encoding/json.

// controls

JSON Input

Paste a JSON payload and generate typed definitions.

vultio · -json-to-go-

Generated Output

Structs ready to copy.

type Profile struct {
  DisplayName string `json:"displayName"`
  SignupAt string `json:"signupAt"`
}

type RootPayload struct {
  Id int `json:"id"`
  Email string `json:"email"`
  IsActive bool `json:"isActive"`
  Roles []string `json:"roles"`
  Profile Profile `json:"profile"`
}
§ 01
context

Why use an online JSON to Go struct converter

Writing Go structs for a JSON API by hand is slow and error-prone: every field needs an exported PascalCase name, the right Go type and a json tag that matches the original key exactly. Miss one tag and encoding/json silently leaves the field empty.

This JSON to Go struct converter does that first pass for you. Paste a real response from the API you are integrating and you get one struct per JSON object, with json:"key" tags that keep the original key names, so json.Unmarshal fills every field on the first try.

Conversion runs entirely in your browser. That matters for Go backend work, where the JSON you paste is often a production payload with IDs, emails or tokens in it.

§ 02
scenarios

JSON to Go struct converter use cases

01 →Generate structs for a third-party REST API response before writing the client in your Go service.
02 →Model webhook payloads (Stripe, GitHub, Slack) so your HTTP handler can json.Unmarshal them into typed values.
03 →Create request and response types for a new internal endpoint from an example agreed with the frontend team.
04 →Bootstrap config structs from an existing JSON configuration file for a CLI tool.
05 →Turn a JSON fixture into a struct for table-driven tests.
§ 03
examples

JSON to Go struct converter examples: input and output

Flat object with json tags

$ input
{"id":1,"name":"Demo","active":true,"score":9.5}
↳ output
type RootPayload struct { Id int `json:"id"` Name string `json:"name"` Active bool `json:"active"` Score float64 `json:"score"` }

Nested object and string slice

$ input
{"tags":["go","api"],"owner":{"login":"octo"}}
↳ output
type Owner struct { Login string `json:"login"` } type RootPayload struct { Tags []string `json:"tags"` Owner Owner `json:"owner"` }

snake_case keys stay intact in the tag

$ input
{"created_at":"2026-01-02T10:00:00Z","user_id":42}
↳ output
type RootPayload struct { CreatedAt string `json:"created_at"` UserId int `json:"user_id"` }
§ 04
troubleshooting

Common JSON to Go struct converter errors and how to fix them

! Fields are always empty after json.Unmarshal

cause:The struct fields are unexported (lowercase) or the json tag does not match the key, so encoding/json skips them.

fix:Keep the generated PascalCase field names and json tags; if you rename a field, leave the tag unchanged.

! json: cannot unmarshal number 1.5 into Go struct field of type int

cause:The sample only contained whole numbers, so the field was inferred as int, but real data has decimals.

fix:Change the field to float64, or paste a sample that contains a decimal value for that field.

! Field typed as interface{}

cause:The value was null or an empty array in the sample, so there was nothing to infer the type from.

fix:Replace interface{} with the real type, using a pointer (*string, *int) when the field can be null.

§ 05
workflow

How developers use the JSON to Go struct converter in practice

→ Rename initialisms to Go style

The generator produces Id, Url and UserId. Go convention (and golint) prefers ID, URL and UserID — rename the field and keep the json tag as it is.

→ Add omitempty for optional output fields

When you marshal structs back to JSON, append ,omitempty to the tag of optional fields (json:"nickname,omitempty") so zero values are not sent.

→ Use time.Time for timestamps

RFC 3339 strings such as 2026-01-02T10:00:00Z are inferred as string. Switch them to time.Time and encoding/json will parse them automatically.

§ 06
tradeoffs

When not to use the JSON to Go struct converter

01 →When the API publishes an OpenAPI spec: generate the Go client from the spec instead, it covers every optional field and enum.
02 →When the payload is polymorphic (a field that is sometimes an object, sometimes a string): you will need json.RawMessage or a custom UnmarshalJSON.
§ 07
limits

JSON to Go struct converter limits and implementation notes

~ One sample, one shape

Only fields present in the pasted JSON appear in the struct. Merge several samples by hand if responses vary.

~ Arrays use the first element

Slice element types are inferred from the first item; heterogeneous arrays need manual typing.

§ 08
read more

Related guides

§ 09
references

Standards & references

§ 10
toolbox

Related developer tools

§ FAQ
questions

Frequently asked questions about the JSON to Go struct converter

How do I convert JSON to a Go struct?

Paste a representative JSON payload in the input. The converter infers a Go type for every field and emits one struct per JSON object, with a `json:"key"` tag that preserves the original key name for encoding/json.


How are JSON numbers mapped to Go types?

Whole numbers become int and numbers with a fractional part become float64. If a field can hold both in real data (for example 1 and 1.5), change it to float64 by hand, since inference only sees the sample you paste.


Why are field names converted to PascalCase?

encoding/json only reads and writes exported fields, and a Go field is exported only when it starts with an uppercase letter. The json tag keeps the original lowercase or snake_case key, so marshalling round-trips correctly.


How are nested objects and arrays handled?

Every nested object becomes its own named struct, and arrays become slices of the type of their first element ([]string, []Item). An empty array becomes []interface{} because there is no element to infer from.


What happens with null values?

A null field becomes interface{} because its real type cannot be inferred. Replace it with a pointer type such as *string or *int once you know what the field holds, so absence and zero values stay distinguishable.


Is my JSON sent to a server?

No. Conversion runs entirely in your browser, so API responses with tokens or customer data never leave your machine.


When should I use omitempty in Go JSON struct tags?

Add `,omitempty` to a struct tag (such as `json:"description,omitempty"`) when you want Go to omit that field from JSON serialization when its value is empty, zero, false, or nil.