Skip to content

JSON to Go Struct

Convert JSON data to Go struct definitions with proper field names, types, and json tags

Stop Typing Struct Definitions by Hand

You’ve got a third-party API that returns a 20-field JSON object with three levels of nesting. You need Go structs to unmarshal it. Writing them manually means staring at the JSON, counting fields, getting the types right, capitalizing every field name to PascalCase, adding json:"original_name" tags so encoding/json knows what to map… it’s 15 minutes of tedious, error-prone typing.

Paste the JSON here. You get Go structs with correct type mappings (string, int, float64, bool, interface{} for nulls), exported PascalCase field names, json struct tags preserving the original keys, and separate named structs for nested objects.

type Root struct {
    UserName string `json:"user_name"`
    Age      int    `json:"age"`
    IsActive bool   `json:"is_active"`
}

Copy, paste into your Go file, and you’re coding in 30 seconds instead of 15 minutes.

After You Generate

The output is a starting point. You’ll probably want to:

  • Add bson, db, or yaml struct tags if you’re using MongoDB, GORM, or Viper
  • Replace interface{} with concrete types where you know the actual schema
  • Add validation tags from libraries like go-playground/validator
  • Rename the root struct from Root to something meaningful like UserResponse

For arrays, the type is inferred from the first element. If your array contains mixed types (which is valid JSON but unusual), you’ll need to adjust the generated code.

Where This Saves Real Time

Consuming external APIs. You’re integrating with a payment provider, a weather service, or a social media API. Their docs show JSON examples. Paste the example, get your structs, and start writing your HTTP client.

Config file parsing. Your Go app reads a JSON config file. Paste a sample config and generate the struct that json.Unmarshal needs.

Microservice contracts. Your gRPC service receives JSON-encoded payloads. Generate request and response structs from sample payloads.

For TypeScript interfaces from the same JSON, the JSON to TypeScript converter handles that. For Python dataclasses, use the JSON to Python Dataclass tool. All three share a similar flow — paste JSON, get typed code.

Everything runs in your browser. No data transmitted.

json go golang struct converter

Related Tools

More in Data Tools