Go JSON

How do I use Go struct tags to rename JSON fields?

In Go, use struct tags to specify JSON field names different from struct field names. Add json:"desiredName" after field declarations: type User struct { FullName string `json:"full_name"` }. This marshals FullName to "full_name" in JSON. Use camelCase or snake_case to match your API conventions. Multiple tags are comma-separated: `json:"email,omitempty"` makes field optional. The dash excludes fields: `json:"-"` prevents field from appearing in JSON output. For embedded structs, tags control flattening behavior. Always use backticks for raw string literals in tags. Common tags include omitempty to skip zero values, string to force string encoding of numbers, and inline for struct embedding. Test your struct marshaling with our JSON Formatter at jsonconsole.com/json-formatter to verify output matches expectations. Proper tag usage creates clean APIs and maintains Go naming conventions internally while exposing idiomatic JSON externally. Tags are essential for professional Go API development.
Last updated: December 23, 2025

Still have questions?

Can't find the answer you're looking for? Please reach out to our support team.