JSON to Go Struct

FreePrivateInstant
JSON input
Go struct
Ctrl+Enter Generate Struct

JSON to Go Struct Generator

Convert a JSON object into Go struct definitions with proper json: tags. Nested objects become separate named structs. Works with any JSON shape — API responses, config files, or event payloads. Runs in your browser with no upload required.

Where Is This Useful?

Unmarshaling API responses
Paste a real API JSON response to get structs you can immediately use with json.Unmarshal(). Each nested object becomes its own named struct with matching json tags.
Building HTTP clients
When you're calling a third-party REST API from Go, the response shape is often documented as JSON. Paste the example response and get typed structs ready for your HTTP client in seconds.
Config and event models
Working with JSON config files or event-driven systems where event payloads are JSON? Generate structs from a sample payload and start building your handler without manual struct writing.

How to Use

  1. Paste a JSON object in the input panel
  2. Set the root struct name (defaults to Root)
  3. Click Generate Struct or press Ctrl+Enter
  4. Copy the output or download as a .go file
  5. Add omitempty and pointer types for optional or nullable fields in your editor

Type Mapping

  • JSON string → string
  • JSON integer → int64
  • JSON float → float64
  • JSON boolean → bool
  • JSON null → interface{}
  • JSON object → named struct with json: tags
  • JSON array → []ElementType

Frequently Asked Questions

What json tags does the generator add?

Every field gets a `json:"fieldname"` tag matching the original JSON key. This ensures encoding/json marshals and unmarshals correctly even if you rename the Go field.

How are nested objects handled?

Nested JSON objects become separate named Go structs, referenced by the parent struct as a field type. The nesting depth is unlimited.

What Go type does a JSON number become?

int64 for integers, float64 for floats. The generator checks whether the value has a fractional part to decide which to use.

What about null values?

JSON null maps to interface{}. In production you may want pointer types like *string or sql.NullString depending on your use case.

Can I use this for API responses?

Yes. Paste a real API response, generate the structs, then use json.Unmarshal() or json.NewDecoder() with the generated type in your HTTP client.

Is my JSON uploaded anywhere?

No. All processing runs locally in your browser.

Related Tools