JSON to Go Converter

Generates idiomatic Go struct definitions from any JSON object or array, automatically handling nested objects as separate named structs and arrays as typed slices. Options let you include json:"..." tags, use pointer types for nested structs, and scaffold a main function with a usage example. The output is ready to compile and can be saved as a .go file without any account or server call.

Input

JSON

Struct Name

Code Style

1 root object, 6 properties
Output

Go Code

What is JSON to Go Converter?

Go's strict type system means every JSON API integration starts with the same ritual: read the response, sketch out a struct, add json tags, realise you missed a field, repeat. This tool short-circuits that process — paste the JSON response and get a complete set of Go struct definitions with properly formatted json struct tags, PascalCase field names following Go conventions, and correct type mappings: int64 for integers, float64 for decimals, bool for booleans, string for text, and slice or pointer types for arrays and nullable fields. Nested objects produce separate named structs in dependency order, ready to paste into your Go source file as-is. The generated structs are compatible with encoding/json, and the json tags match the original key names exactly. Works with Gin, Echo, Fiber, and any framework that uses encoding/json under the hood.

How to Use

  1. 1

    Paste Your JSON

    Paste a JSON object or array into the editor. For accurate type inference on arrays, include several representative items. Nested objects and arrays of objects are both handled.

  2. 2

    Configure Go Output

    Set the root struct name, choose whether to generate json tags (always recommended for serialisation), and optionally enable omitempty for all fields or only nullable ones.

  3. 3

    Generate Go Structs

    Click "Generate Go Structs". Field names are converted from camelCase or snake_case to PascalCase, types are inferred (int64, float64, bool, string, []T), and json struct tags are generated matching the original JSON key names.

  4. 4

    Copy into Your Go Package

    Copy the generated struct definitions and paste them into your Go package. Add the encoding/json import and use json.Unmarshal(data, &result) or json.NewDecoder(r.Body).Decode(&result) to deserialise.

Common Use Cases

Go REST API Handlers

Generate Go structs from JSON request/response payloads to use in net/http or Gin handlers with json.Unmarshal, enabling type-safe request binding and response serialisation.

gRPC & Protobuf Development

Use generated Go structs as a starting point for defining protobuf message types or as intermediate types when converting between JSON and binary proto formats in gRPC services.

CLI Tool Development

When building Go CLI tools that consume JSON APIs or config files, generate struct definitions from sample payloads to enable strongly-typed configuration parsing with encoding/json.

Microservice Contract Definition

Define service contracts by generating Go structs from JSON schema samples shared between teams, ensuring consistent field names, types, and JSON tags across multiple microservices.

Conversion Examples

JSON Object → Go Struct

A JSON object generates a Go struct with json tags for serialisation.

Input JSON

{
  "id": 1,
  "username": "alice",
  "email": "alice@example.com",
  "is_active": true
}

Output CSV

type Root struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	IsActive bool   `json:"is_active"`
}

Nested JSON → Nested Go Structs

Nested objects generate separate Go structs with pointer or value references.

Input JSON

{
  "user": {"id": 1, "name": "Alice"},
  "items": [{"sku": "ABC", "qty": 2, "price": 9.99}]
}

Output CSV

type User struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type Item struct {
	Sku   string  `json:"sku"`
	Qty   int     `json:"qty"`
	Price float64 `json:"price"`
}

type Root struct {
	User  User   `json:"user"`
	Items []Item `json:"items"`
}

Frequently Asked Questions