Convertful
ImagePDFVideoUtilityBlog

Image Tools

  • Compress Image
  • Resize Image
  • Remove Background
  • HEIC to JPG
  • All Image Tools →

PDF Tools

  • Compress PDF
  • Merge PDFs
  • Split PDF
  • PDF to Images
  • All PDF Tools →

Video & Audio

  • Video to GIF
  • Compress Video
  • Trim Video
  • Extract Audio
  • All Video Tools →

Utility

  • QR Code Generator
  • JSON Formatter
  • Color Converter
  • All Utility Tools →
All processing happens in your browser. Your files never leave your device.
AboutBlogTermsPrivacyContact
© 2026 Convertful. All rights reserved.
HomeUtilityJSON to Go Struct

JSON to Go Struct Generator

Generate Go structs with JSON tags from a sample. Free, private, runs in your browser.

100% private — your files never leave your browser. All processing happens locally on your device.

Settings

Paste JSON above to generate a Go struct.

You might also need

JSON to TypeScriptGenerate TypeScript interfaces from a JSON sample
JSON to Python Dataclass / TypedDictGenerate @dataclass or TypedDict classes from JSON
JSON FormatterFormat and validate JSON data
JSON Diff CheckerCompare two JSON documents semantically

Typed Go Structs From A JSON Sample

Go's strong typing rewards explicit struct definitions. Having to handwrite a 40-field struct for an API response is tedious and error-prone. This tool does the tedious part: paste a sample response and get a struct with PascalCase exported field names, correct Go types, and `` `json:"..."` `` tags matching the original JSON keys. The result is ready to drop into any Go project — no dependencies beyond the standard `encoding/json` package.

Nested Structs, Slices, And Pointers

Nested JSON objects become named sub-structs referenced from the parent field. `{"addr":{"city":"NYC"}}` yields a `Root` struct with an `Addr Addr` field and an `Addr` struct with a `City string` field. JSON arrays become Go slices (`[]string`, `[]int`). Null values in the sample yield `*interface{}` with `omitempty` on the json tag — the pointer captures the nullable-ness, and `omitempty` ensures JSON output doesn't include the field when the pointer is nil.

Numeric Type Choices

JSON has one number type; Go has many. The tool defaults to `int` for whole numbers and `float64` for numbers with a fractional part. If you need `int32` or `int64` for protocol-level reasons, adjust by hand after generation — the inference is heuristic, not protocol-aware. For unsigned integers, timestamps, or fixed-precision decimals, use the generated struct as a starting point and tune the types to match your storage layer.

Idiomatic Field Casing

Go convention is PascalCase for exported struct fields. JSON convention is often snake_case or camelCase. The tool converts aggressively: `user_name` → `UserName`, `emailAddress` → `EmailAddress`. The original key is preserved on the `json` tag so marshalling produces the exact key your JSON source expected. If the original key was invalid Go (e.g., started with a digit), the tool prefixes an underscore to keep the generated code compilable.

FAQ

Does it use PascalCase field names?

Yes. JSON keys like `user_name` become `UserName` on the struct; the original key is preserved in the json tag (`` `json:"user_name"` ``). This matches idiomatic Go exported-field conventions.

How are nullable fields handled?

Null values in the sample JSON emit `*interface{}` with `omitempty`. When you have a more specific sample (e.g., `"count": null` or `"count": 3`), consider tweaking the emitted pointer type to `*int`.

What about numeric types?

Whole numbers become `int`; numbers with a fractional part become `float64`. If you need a specific width (`int32`, `int64`, `uint`), adjust after generating.

Are arrays emitted as slices?

Yes. `["a","b"]` becomes `[]string`. Heterogeneous arrays fall back to `[]interface{}`.