JSON to Go Struct

Paste JSON to generate idiomatic Go struct definitions with json tags and proper naming conventions.

About This Tool

The JSON to Go Struct converter is a free browser-based tool that automatically generates idiomatic Go struct definitions from any JSON data. Instead of manually writing struct types for API responses, configuration files, or database records, you can paste the raw JSON and get accurate, ready-to-use Go code in milliseconds.

The converter performs recursive type inference across your entire JSON structure. Primitive values are mapped to their corresponding Go types — string, int64, float64, and bool. Nested objects are extracted into their own named structs, with names derived from the field key using PascalCase conversion. For example, a field called shipping_address produces a ShippingAddress struct. Common Go acronyms like ID, URL, HTTP, JSON, and API are automatically uppercased following Go naming conventions.

All processing happens entirely in your browser. Your JSON data never leaves your machine — there are no server round-trips, no logging, and no third-party analytics on your input. This makes it safe for sensitive payloads such as internal API responses, authentication tokens, and configuration files that contain secrets.

Additional options let you customize the output to match your project's coding standards. You can toggle between separate named structs and inline nested structs, add omitempty to all json tags for optional serialization, or enable pointer types for nullable fields. Every field includes a proper json:"fieldName" tag that preserves the original JSON key name, ensuring seamless marshaling and unmarshaling with Go's encoding/json package.

How to Use

  1. Paste or type your JSON into the JSON Input panel on the left.
  2. The Go struct output updates automatically in the right panel as you type.
  3. Set the Root struct name to customize the top-level struct name (defaults to "AutoGenerated").
  4. Click the inline toggle to embed nested structs directly inside the parent struct instead of generating separate named types.
  5. Enable omitempty to add the omitempty option to all json struct tags.
  6. Enable *nullable to use pointer types for fields that are null in the JSON input.
  7. Click Copy or press Ctrl+Shift+C to copy the generated Go code to your clipboard. Use Sample to load example JSON.

Popular JSON to Go Examples

View all 15 JSON to Go examples →

FAQ

How does the tool handle nested JSON objects?

By default, each nested object is extracted into its own named Go struct. The name is derived from the field key using PascalCase conversion. For example, a field called billing_address produces a BillingAddress struct. If a name collision occurs (e.g. two fields that both normalize to "Address"), a numeric suffix is appended automatically (Address, Address2, etc.). You can also enable the inline option to embed nested structs directly in the parent.

How are JSON keys converted to Go field names?

JSON keys in snake_case, camelCase, and kebab-case are all converted to PascalCase (exported Go names). Common Go acronyms like ID, URL, HTTP, JSON, API, and UUID are automatically uppercased following Go community conventions. The original JSON key is always preserved in the json:"..." struct tag.

How are JSON number types mapped to Go types?

Numbers without a fractional part (e.g. 42, -7) are mapped to int64. Numbers with decimals (e.g. 3.14) are mapped to float64. This provides safe defaults for most use cases. You can manually adjust the types in the generated code if you need int32, uint64, or other numeric types.

What happens with null values in JSON?

By default, null values are mapped to interface{} since the actual type cannot be inferred. If you enable the *nullable option, null fields use a pointer type (*interface{}) instead, which is the idiomatic Go approach for distinguishing between zero values and absent values during JSON unmarshaling.

How are arrays handled?

The element type is inferred from the first element in the array. For example, an array of strings becomes []string, and an array of objects becomes a slice of the corresponding struct type. Empty arrays default to []interface{} since the element type cannot be determined.

Is my data safe?

Yes. All type inference and code generation runs entirely in your browser using JavaScript. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.

What is the difference between inline and separate structs?

With separate structs (default), each nested object gets its own top-level type ... struct definition. This is cleaner when you need to reference the same type in multiple places. With inline structs, nested objects are defined directly inside the parent struct using anonymous struct syntax. This is useful for one-off API responses where you want everything in a single definition.

Related Tools