JSON To Go Generator

Need to convert Go into JSON Schema?

Go Struct → JSON Schema

JSON Input

Loading editor…

Generated Go

Configuration

Enter JSON data to generate Go structs

Structs with proper field names and JSON tags

How to convert JSON to Go – step-by-step guide

Use this JSON to Go generator to create Go structs with JSON tags from JSON samples for APIs and services.

  1. Step 1 – Paste a JSON sample

    • Paste a representative JSON object or array into the left editor.
    • Include nested objects, arrays, and nullable fields so types are inferred correctly.
    • Use Import to load JSON from a file, URL, or sample data.
  2. Step 2 – Choose Go struct options

    • Set a root Struct Name (for example Root).
    • Decide how to handle optional fields (*string, omitempty, or custom types).
    • Confirm JSON tags and naming so keys map correctly (for example json:"createdAt").
  3. Step 3 – Review the generated code

    • Check field names, types, and how arrays/objects are modeled.
    • Adjust options like Root Type Name, null handling, and frameworks if available.
    • If a field is inferred incorrectly, tweak your sample JSON and regenerate.
  4. Step 4 – Use the structs in Go

    • Paste the structs into your package and run gofmt.
    • Unmarshal with encoding/json into the root type.
    • Add validation (for example required fields) at the API boundary.
  5. Step 5 – Copy or download

    • Copy the output into your project or download it as a file.
    • Run your formatter/linter to match your code style.
    • Add JSON parsing/serialization libraries if your language requires them.

Quick tips

  • Use pointers for nullable fields when you need to distinguish missing vs empty.
  • Prefer time.Time only when you control the timestamp format.
  • Keep DTO structs separate from internal domain models when needed.
Example output (simplified)
// JSON input
{
  "id": 123,
  "name": "Maeve Winters",
  "email": "maeve@example.com",
  "active": true,
  "roles": ["admin", "editor"],
  "metadata": { "plan": "pro" },
  "createdAt": "2024-03-01T10:15:00Z",
  "score": 99.5,
  "notes": null
}

// Generated Go structs (simplified)
type Metadata struct {
  Plan string `json:"plan"`
}

type Root struct {
  ID        int       `json:"id"`
  Name      string    `json:"name"`
  Email     *string   `json:"email"`
  Active    bool      `json:"active"`
  Roles     []string  `json:"roles"`
  Metadata  Metadata  `json:"metadata"`
  CreatedAt string    `json:"createdAt"`
  Score     float64   `json:"score"`
  Notes     any       `json:"notes"`
}

Related JSON & Go tools

Explore more JSON and schema tools that work great alongside this JSON to Go generator.

Frequently Asked Questions

What Go features are supported?

The generator creates Go structs with proper field names, JSON tags for marshaling/unmarshaling, and appropriate Go data types following Go naming conventions.

How are JSON tags handled?

The generator automatically adds JSON tags to struct fields for proper serialization. You can also enable YAML or XML tags if needed for multi-format support.

Can I customize the package name?

Yes! You can specify any package name in the options. The default is 'main' but you can use your own package names like 'models', 'types', etc.

How are Go naming conventions handled?

The generator automatically converts JSON field names to proper Go field names (PascalCase for exported fields) while preserving the original names in JSON tags.

JSON to Go Struct Generator Online | JSONSwiss