Go Struct Tag Generator & Validator
Generate conventional json, yaml, xml, db, and validation tags for named Go struct fields, or validate tag key/value syntax, duplicates, quoting, and options before using the code.
Go Struct Tag Generator & Validator workspace
Generated field declarations will appear here.
The generator handles one named field per line. Always confirm package-specific tag options against that package’s documentation.
Go Struct Tag Generator & Validator example
Generated with snake_case naming, json and yaml keys, and omitempty enabled.
Example input
UserID int
DisplayName string
CreatedAt time.TimeExpected output
UserID int `json:"user_id,omitempty" yaml:"user_id,omitempty"`
DisplayName string `json:"display_name,omitempty" yaml:"display_name,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty" yaml:"created_at,omitempty"`How to use Go Struct Tag Generator & Validator
- 1
Choose Generate and paste one exported named field and type per line.
- 2
Select json, yaml, xml, or db keys and choose snake_case or camelCase naming.
- 3
Optionally add omitempty and validate:required, then generate the tagged field declarations.
- 4
Copy or download the result and run gofmt in your project.
- 5
Switch to Validate to inspect an existing tag, review parsed keys and options, and correct every reported issue.
What this tool does
Generate mode reads one named Go field per line, derives snake_case or camelCase external names, and appends selected tag keys. It can add omitempty to serialization tags and validate:"required" when requested.
Validate mode accepts a backtick-delimited tag, raw tag contents, or complete field lines containing backtick tags. It parses conventional space-separated key:"value" pairs, decodes Go quoted-string escapes, lists names and comma options, and reports structural issues.
All work is deterministic and local. The validator checks conventional reflect.StructTag format, but package-specific meanings still come from packages such as encoding/json, encoding/xml, YAML libraries, validators, or database mappers.
Features and options
- Multiple tag keys per field
- snake_case and camelCase naming
- json, yaml, xml, and db presets
- omitempty option generation
- validate:required generation
- Conventional reflect.StructTag validation
- Duplicate key and option detection
- Go quoted-string escape decoding
- Complete field-line tag extraction
- Local copy and download
Technical information
The Go specification permits an optional string-literal tag after a struct field declaration. The reflect package expects a conventional format made of space-separated key:"value" pairs where each value follows Go quoted-string syntax.
encoding/json interprets the json value as a comma-separated field name and options. Its omitempty behavior is package-defined; other packages can assign different meanings to the same option text.
The generator intentionally accepts one named field per line. It does not parse embedded fields, grouped names, comments containing unusual delimiters, build constraints, generic type declarations, or a complete Go abstract syntax tree.
Common use cases
- Adding JSON and YAML names to data models
- Creating database mapping tags
- Checking duplicate tag keys
- Finding missing spaces or quotes
- Reviewing omitempty usage
- Normalizing external field naming
- Preparing a first draft before gofmt and tests
Limitations
- Generated yaml, db, and validate semantics depend on third-party packages and must be checked against the chosen package.
- The generator handles one named field per line and does not expand embedded or comma-grouped fields.
- It does not run gofmt, go vet, a compiler, or package-specific validators.
- A conventionally valid tag can still contain an unsupported name or option for a particular package.
- Unexported fields may be ignored by encoders even when a tag is present.
Related tools
References & Sources
Defines Go field declarations and the optional string-literal tag attached to a struct field.
Verified 2026-08-13 ↗pkg.go.dev · Official DocumentationGo reflect.StructTagDocuments the conventional tag format and the Get and Lookup behavior used by reflection clients.
Verified 2026-08-13 ↗pkg.go.dev · Official DocumentationGo encoding/json PackageDefines json struct-tag field names and options, including omitempty behavior.
Verified 2026-08-13 ↗pkg.go.dev · Official DocumentationGo encoding/xml PackageDocuments the distinct field-path and option rules interpreted for xml struct tags.
Verified 2026-08-13 ↗Go Struct Tag Generator & Validator FAQ
What is a Go struct tag?
It is an optional string literal attached to a struct field. Reflection exposes it to packages that define conventions for keys such as json or xml.
Does omitempty mean the same thing for every package?
No. The option is interpreted by the package reading the tag. encoding/json documents its own empty-value rules; YAML, XML, and other packages can differ.
Why does the generator use one field per line?
That focused input avoids guessing how grouped or embedded declarations should receive tags and keeps generated edits easy to review.
Does valid mean my Go program will compile?
No. Validation checks conventional tag syntax. The surrounding field declaration, type, package-specific options, and complete program still need gofmt, go vet, tests, and compilation.
Can unexported fields use generated tags?
A tag can be written, but many encoders such as encoding/json ignore unexported fields. Review field visibility for the target package.
Does the tool understand every validator or ORM tag?
No. It can generate a small preset and validate conventional quoting, but third-party key names and option semantics belong to their package documentation.