JSON to Go Struct
Generates a minimal, readable Go struct from a JSON sample, with json tags preserved and a
nested struct for every nested object.
About This Tool
Turns a JSON response or payload into a ready-to-paste Go struct, matching the shape you'd need to
unmarshal that same JSON with encoding/json: useful when wiring up a Go client or server
against an API whose schema you don't control. Nested objects become their own nested struct
automatically, and the panel also runs in reverse, generating mock JSON from a pasted struct.
Types are inferred from one example, not a full schema, so this is a starting point for struct definitions rather than a generator for validated API contracts. For a TypeScript equivalent, use JSON to TypeScript; for Python, use JSON to Python.
Key Features
- Direction toggle: JSON → Go, or parse a pasted struct back into mock JSON.
- Configurable struct name: names the root type; nested structs inherit
{Name}{Field}. - Automatic PascalCase field names: arbitrary JSON keys become exported Go identifiers, with the original key kept in the
jsontag. - Int64 vs float64 inference: whole numbers vs. numbers with a fractional part.
- File upload & drag-and-drop: load a
.jsonor.gofile directly.
Example
{"id": 1, "name": "Ada", "address": {"city": "Lagos"}} produces:
type Root struct {
Id int64 `json:"id"`
Name string `json:"name"`
Address RootAddress `json:"address"`
}
type RootAddress struct {
City string `json:"city"`
} FAQ
- Can I convert Go structs back to JSON?
- Yes! Click the ⇌ swap button or toggle the Direction dropdown to generate mock JSON from any Go struct definition.
- How are numbers typed?
- A whole number becomes
int64; a number with a fractional part becomesfloat64. This is inferred from the sample, not guaranteed for every possible value the field could hold. - What happens to a field observed as
null? - It becomes
any, since a single null sample carries no concrete type information. - Are invalid or reserved field names handled?
- Yes. Keys are converted to exported PascalCase Go identifiers; the original key is preserved exactly in the
jsontag. - Is the generated code executed?
- No. It is text output only, never compiled or run.