🐹

JSON to Go Struct

Convert sample JSON to Go structs with json tags, nested types and omitempty option. Supports JSON to Go, golang struct generator. Runs locally — no data uploaded. Free at oltool.net.

0 struct
JSON
Go
type Profile struct {
	Age int `json:"age"`
	City string `json:"city"`
}

type AutoGenerated struct {
	ID int `json:"id"`
	Name string `json:"name"`
	Active bool `json:"active"`
	Score float64 `json:"score"`
	Tags []string `json:"tags"`
	Profile *Profile `json:"profile"`
}

About JSON to Go Struct

Go is strongly typed, so consuming a JSON API means defining matching structs first — slow and easy to mistype json tags. This tool parses your sample JSON locally in the browser and generates Go structs with json tags: field names become exported PascalCase, nested objects split into their own structs, arrays infer to slice types, with an optional omitempty switch. Nothing is uploaded. Tip: Bookmark this tool for quick access whenever you need format conversion. All processing happens locally in your browser — no data upload, so feel free to paste sensitive content.

Use Cases

  • Consume REST APIs — Paste the JSON an API returns and instantly get a Go struct ready to Unmarshal into.
  • Define config structs — Generate a struct from a config sample to load YAML/JSON configuration.
  • Build scrapers/collectors — Model third-party responses quickly and skip hand-writing fields.
  • Bootstrap gRPC/messages — Reverse-engineer a structure from sample data as a starting point for messages or DTOs.
  • Learn Go type mapping — See at a glance which Go types map to each JSON type to aid learning.
  • Model AWS SDK payloads — Paste an AWS SDK response JSON and generate Go structs for typed unmarshaling in Lambda functions.
  • Generate API client types — Create Go structs from a REST API sample to build a typed client library without manual mapping.

FAQ

How are field names converted?

They become exported PascalCase per Go conventions, with common initialisms like Id/URL/API uppercased, while keeping the original json tag.

What does a null value infer to?

null infers to interface{} since the concrete type is unknown. Use a non-null sample for a more precise type.

What is omitempty for?

When enabled it appends ,omitempty to the json tag so empty fields are omitted on marshal — handy when many fields are optional.

How are nested objects handled?

Each nested object becomes its own named struct, referenced by pointer from the parent — clean and reusable.

Do I need to adjust the output?

It is standard Go code you can rename, retype or comment after copying. Integers default to int and decimals to float64; change to int64 etc. as needed.

Any browser compatibility requirements?

This tool works in all modern browsers (Chrome, Firefox, Edge, Safari). No plugins or extensions required.

Can I use it offline?

After initial load, most features work offline. The core logic runs entirely in your browser with no network dependency.