JSON to Go Struct

Generate Go structs with multiple struct tags from any JSON object.

Struct Tags

What is a Go Struct with JSON Tags?

In Go, JSON deserialization uses struct tags to map JSON keys to Go fields. A struct tag like `json:"first_name"` tells encoding/json to map the JSON key first_name to the Go field FirstName. Without the tag, Go requires the field name to exactly match the JSON key (case-insensitive).

Writing Go struct definitions by hand for complex JSON responses is tedious. This tool generates the complete struct hierarchy from any JSON — including nested structs, slice types, and proper json: tags for every field. Paste any JSON object or API response and get ready-to-use Go types in seconds.

JSON to Go Struct Example

Input JSON:

json
{
  "id": 1,
  "name": "Ravi Kumar",
  "active": true,
  "address": { "city": "Surat", "country": "IN" }
}

Generated Go struct:

go
type RootAddress struct {
	City    string `json:"city"`
	Country string `json:"country"`
}

type Root struct {
	Id      int64       `json:"id"`
	Name    string      `json:"name"`
	Active  bool        `json:"active"`
	Address RootAddress `json:"address"`
}

JSON to Go Type Mapping

JSON typeGo typeNotes
stringstringMapped directly
integer numberint64Whole numbers use int64 for safety
float numberfloat64Decimal numbers use float64
booleanbooltrue/false → bool
nullinterface{}Nullable fields use the empty interface
objectStruct (named)Nested objects become separate named structs
array of objects[]StructNameTyped slice based on first element
array of strings[]stringPrimitive arrays use typed slices

Common Use Cases

  • REST API integrationPaste an API response JSON and instantly get the Go struct needed to decode it with encoding/json.
  • Database model generationConvert a database record JSON to a Go struct for use with sqlx or GORM.
  • Config file parsingGenerate a Config struct from a sample config.json to use with json.Unmarshal.
  • gRPC / protobuf bridgingCreate Go types for JSON bridging layers between REST and gRPC services.

Using the generated struct:

go
import "encoding/json"

var result Root
err := json.Unmarshal([]byte(data), &result)
if err != nil {
    log.Fatal(err)
}
fmt.Println(result.Name)

Frequently Asked Questions

int64 is the safest default for integers in Go — it avoids overflow on 32-bit systems and matches the range of JSON numbers. You can change it to int or int32 in your code as needed.

JSON null is mapped to interface{} since Go has no direct null type for structs. If you expect nullability, replace interface{} with a pointer type like *string or *int64.

Yes. Field names are converted to PascalCase (CamelCase) as required by Go's exported field convention. The original JSON key is preserved in the json struct tag.

Yes. The generated structs use encoding/json compatible json tags and work directly with json.Marshal and json.Unmarshal from the Go standard library.

Related Tools