JSON to Go Struct

JSON Tools

How to use the JSON to Go Struct

Generate Go structs in seconds:

1

Paste your JSON

Paste any JSON object into the input. The generator reads the structure and infers Go types from the values.

2

Set the root struct name

Enter the name for the root struct (default: 'Root'). Nested objects get their own struct names derived from the key name.

3

Click Generate

Go struct definitions appear with json:"fieldname" struct tags and PascalCase field names matching Go naming conventions.

4

Copy into your project

Paste the structs into your Go file and use json.Unmarshal() or json.NewDecoder() to decode your JSON into the generated struct.


When to use this tool

Go requires explicit struct definitions for JSON unmarshalling. Use this tool when:

  • Building a Go service that consumes a third-party REST API and needs to unmarshal the JSON response
  • Writing Go tests that need struct types matching your JSON fixtures
  • Starting a new Go project that works with existing JSON data sources
  • Converting an OpenAPI or Swagger JSON schema to Go structs for your service layer
  • Quickly prototyping a Go API handler for a JSON payload from Postman or curl

Frequently asked questions

Q:What Go types are inferred from JSON?
JSON strings become string, integers become int64, floats become float64, booleans become bool, null values become interface{} (update to pointer types like *string for production), arrays become []Type, and objects become named structs.
Q:Are json struct tags included?
Yes. Every field includes a json:"fieldname" struct tag matching the original JSON key. This ensures json.Marshal() and json.Unmarshal() work correctly even when Go field names differ from JSON keys due to PascalCase conversion.
Q:How are null values handled in Go?
JSON null values are typed as interface{} by default since Go doesn't have nullable primitives. For production code, change these to pointer types (*string, *int64) or use sql.NullString if the data comes from a database.
Q:Does it handle arrays of mixed types?
JSON arrays with mixed types (e.g. [1, "two", true]) are typed as []interface{} since Go arrays must have a single element type. Arrays of objects generate a typed slice with a named struct for the element.