Skip to content

Go Tools

JSON to Go Struct Converter

Turn a JSON payload into typed Go structs with correct json tags.

json to goRuns in your browserUpdated 2026-09-22

JSON input

437 chars

Go output

3 types, 14 fields
type APIKeyItem struct {
	ID         string   `json:"id"`
	LastUsedIP *string  `json:"last_used_ip"`
	Scopes     []string `json:"scopes"`
}

type ProfileItem struct {
	AvatarURL   string `json:"avatar_url"`
	DisplayName string `json:"display_name"`
	Timezone    string `json:"timezone"`
}

type RootItem struct {
	APIKeys    []APIKeyItem `json:"api_keys"`
	Balance    float64      `json:"balance"`
	CreatedAt  string       `json:"created_at"`
	DeletedAt  interface{}  `json:"deleted_at"`
	IsActive   bool         `json:"is_active"`
	LoginCount float64      `json:"login_count"`
	Profile    ProfileItem  `json:"profile"`
	UserID     string       `json:"user_id"`
}
Change the sample so every optional field appears at least once; a field that is always present in the sample is generated as a value, not a pointer.

About JSON to Go

Writing Go structs for an API response is mechanical work: one type per nested object, one field per key, a json tag for every field, and a decision about pointers wherever a value can be null. It is the kind of task that takes twenty minutes and produces a typo that only shows up at runtime.

This converter parses your JSON, derives a type for the root value, and emits every nested struct it needs. Struct names come from the keys they were found under, repeated shapes are merged into a single type, and the json tags keep the exact keys from your payload so decoding works without further changes.

How it works

  • The JSON is parsed and walked to infer a Go type for every value.
  • Object keys are converted to exported PascalCase field names, and the original key is preserved in a json tag.
  • Nested objects become their own named structs, placed after the root type.
  • Arrays become slices, and arrays of objects produce a slice of the inferred element type.
  • Null values are typed as interface{}, since JSON carries no type for them, and fields that are absent from some objects in an array become pointers when the pointers option is enabled.
  • Numbers are emitted as float64 by default, or as int when the sample contains only whole numbers and the int option is enabled.
  • Shapes that appear more than once with the same field set are merged into one type instead of being duplicated.

Input and output

Accepts

A JSON object, array or scalar value. Paste text or load a local file.

Produces

Go source code with the root struct and all nested types, ready to paste into a package.

Privacy

Parsing and code generation are performed in your browser. Payloads are never uploaded.

JSON to Go FAQ

How are field names converted to Go style?

Snake case, kebab case and dotted keys are split and converted to PascalCase, so user_id becomes UserID and created_at becomes CreatedAt. Common initialisms such as ID, URL and API are kept uppercase.

Why is my numeric field a float64 instead of an int?

JSON does not distinguish integers from decimals, so the safe default is float64. If every observed value is a whole number, enable the int option or change the type manually after generation.

How do I handle optional fields?

Enable omitempty to add that option to every json tag when encoding. Enable pointers so fields that are absent from some objects in an array become pointer types, which keeps an absent value distinguishable from the zero value.

Does it support arrays at the root?

Yes. An array at the root produces a slice type plus the element struct, which you can alias or use directly in your decoder.

What if two objects have different fields for the same key?

The field sets are merged into one struct and missing fields are treated as optional. Review the merged type if the payload is polymorphic, because a union may describe your data better.