WebToolsPlanet
Converter Tools

JSON to Go Struct Converter

Paste a JSON object and get ready-to-use Go structs with proper field names, types, and `json:"..."` tags for `encoding/json`.

Last updated: May 27, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is JSON to Go Struct Converter?

Go's `encoding/json` package uses struct tags to map JSON keys onto exported struct fields. Writing those structs by hand for a large API response is repetitive: each field needs an exported name (Go convention), a Go type, and a `json:"original_key"` tag if the JSON key differs from the Go field name.

This tool reads a JSON example and emits the matching struct hierarchy. Integers within int range become `int`, larger ones become `int64`, decimals become `float64`, and so on. Arrays become slices (`[]T`). Nested objects produce nested struct types. Field names are converted to Go's PascalCase, with Go-style common initialisms (ID, URL, API, HTTP) preserved in uppercase. Tabs align the columns, matching gofmt output.

How to Use JSON to Go Struct Converter

1

Paste a JSON object (root must be an object).

2

Set the root struct name and package name.

3

Toggle json tags and pointer types for nested structs.

4

Copy the generated structs into your project.

Common Use Cases

  • Bootstrapping Go structs for a JSON API client.
  • Generating types for a service consuming JSON config.
  • Converting an OpenAPI example to typed Go structs.
  • Producing model types for sqlx or GORM with JSON columns.

Example Input and Output

A flat JSON object becomes a Go struct with json tags.

JSON input
{ "userId": 42, "name": "Alice", "active": true }
Generated Go struct
type Root struct {
	UserID int    `json:"userId"`
	Name   string `json:"name"`
	Active bool   `json:"active"`
}

Privacy

All conversion happens in your browser. No JSON is sent to a server.

Go formatting

The output uses tab indentation and column alignment matching gofmt. You can copy and paste without re-running gofmt.

Frequently Asked Questions

Why does userId become UserID?
Go convention uses common initialisms in uppercase: ID, URL, API, HTTP, JSON, etc. The tool detects these in your field names and capitalizes them accordingly.
When should I enable pointer types for nested structs?
Pointer types (*T) let nested structs be nil/missing without a zero-value sub-struct. Enable for sparse JSON where many nested objects are optional; leave off for fully populated, predictable shapes.
How are integer types decided?
Integers within int32 range (±2,147,483,647) use int. Larger ones use int64. Decimals use float64. For currency, switch to a precise decimal type after generation.
Does this generate omitempty tags?
No, since presence cannot be inferred from a single example. Add omitempty manually to fields you want to omit when zero.
Does this send my JSON anywhere?
No. All generation happens locally in your browser.