JSONBeautify
    Back to Blog
    January 10, 20254 min read

    JSON to Go Struct: Generate Go Types from JSON Data

    Generator
    Go

    Go's strict typing requires struct definitions for JSON parsing. Our generator creates idiomatic Go structs with proper json tags from your API response data.

    Example Generation

    Input JSON:

    {
      "user_id": 123,
      "full_name": "John Doe",
      "is_admin": false,
      "tags": ["developer", "admin"]
    }

    Generated Go:

    type Root struct {
        UserID   int      `json:"user_id"`
        FullName string   `json:"full_name"`
        IsAdmin  bool     `json:"is_admin"`
        Tags     []string `json:"tags"`
    }

    Key Features

    • PascalCase: Field names converted to Go conventions
    • JSON Tags: Original JSON keys preserved in tags
    • Type Inference: Correct Go types for all JSON values
    • Nested Structs: Complex objects become separate types

    Using Generated Structs

    package main
    
    import (
        "encoding/json"
        "fmt"
    )
    
    func main() {
        jsonData := `{"user_id": 123, "full_name": "John"}`
        
        var user Root
        json.Unmarshal([]byte(jsonData), &user)
        
        fmt.Println(user.FullName) // "John"
    }

    Type Mappings

    • JSON strings → string
    • JSON integers → int
    • JSON floats → float64
    • JSON booleans → bool
    • JSON arrays → []Type
    • JSON objects → Nested structs

    Try It Now

    Head to our JSON to Go Generator and create Go structs from your JSON data!

    © 2025 JSON Formatter. All rights reserved.