JSON to Go Struct

Free

Generate Go struct definitions from JSON data

Go struct
type Root struct {
	Id int `json:"id"`
	Name string `json:"name"`
	Active bool `json:"active"`
}

About JSON to Go Struct

Go's strong typing means consuming a JSON API requires a struct with the right fields and JSON tags, and writing those out for a large response is repetitive busywork. This tool reads a JSON sample and generates Go struct definitions with appropriate types and struct tags so you can unmarshal responses into typed values right away.

Paste a representative JSON object and the converter infers Go types for each field, nests structs for nested objects, and adds json tags matching the original keys. It is free, runs in your browser, needs no signup, and returns the structs instantly. Types come from one sample, so provide a complete example and review numeric types and any fields that could be null or absent before relying on the structs.

Common uses

  • Generating Go structs for a JSON API you unmarshal in your service
  • Creating typed structs with json tags from a sample response
  • Bootstrapping nested structs for a structured JSON payload
  • Saving boilerplate when modeling JSON in a Go project
  • Getting a draft struct to refine for encoding/json

How to use

  1. 1

    Configure options

    Set your preferences using the options panel below.

  2. 2

    Click Generate

    Click the process button to generate your result instantly.

  3. 3

    Copy or download

    Copy the result to clipboard or download it directly to your device.

Why ToolHub?

  • Accurate conversion
  • Multiple formats
  • Instant results

FAQ

Does it add JSON struct tags?

Yes. Each field gets a json tag matching the original key so encoding/json maps it correctly during marshal and unmarshal.

How are numbers typed?

JSON has one number type, so integers and floats are inferred from the sample values. Adjust the chosen Go numeric type if needed.

Are nested objects supported?

Nested objects become embedded or referenced structs, mirroring the JSON hierarchy with typed fields.

What about null or missing fields?

Fields absent or null in the sample may need pointer types or omitempty, since the inferred struct reflects only the example you provide.

Can I use JSON to Go Struct on mobile?

Yes — ToolHub is fully responsive and works on iPhone, Android, tablets and all modern browsers. No app install needed.