What does this tool do?
JSON to Go Struct takes a sample JSON payload and automatically generates the matching Go struct definitions. It maps each field to the right Go type and adds struct tags that preserve the original JSON keys, saving developers who build Go APIs, microservices, and CLI tools from writing structs by hand.
How to use it
- Paste or type your data into the left field.
- The result is generated instantly on the right.
- Use the Copy button to grab the output.
Struct tags and naming
Every generated field carries a `json:"..."` tag that preserves the original JSON key, while the field name itself is converted to PascalCase so it is exported and marshals correctly. Nested objects become their own named structs, and arrays become the appropriate slice type. The result reads like idiomatic Go and compiles straight away when you paste it into a file, with no manual cleanup needed for typical API responses.
How type inference works
The tool inspects each JSON value and chooses the closest Go type: int for whole numbers, float64 for decimals, string for text, and bool for true/false. Fields that mix types or contain null may fall back to interface{} for flexibility. Homogeneous arrays become []T, while irregular ones become []interface{}. This heuristic gives you a working starting point that rarely needs editing for standard payloads.
Frequently asked questions
What does it generate for nested JSON objects?
Each nested object becomes its own named struct, and the parent struct references that type. This keeps the generated code readable and reusable across your project.
Can I edit the generated struct tags?
Yes. The output is plain Go code, so after copying it you can freely add omitempty, rename fields, or attach extra tags such as yaml or bson.
Why does a number come out as float64 instead of int?
JSON does not distinguish numeric kinds, so values with a decimal point map to float64 and whole numbers map to int. If you need one consistent type, adjust the output after copying.
Is JSON to Go Struct free?
Yes. JSON to Go Struct and all 300+ tools on MagmaNex are completely free with no signup or account required.
Is my data safe?
Yes. Everything runs locally in your browser. The data you enter is never sent to a server, stored, or shared.
Does it work on mobile?
Yes. JSON to Go Struct works on phones, tablets and desktops — no app download needed.
🔒 Privacy: everything runs in your browser, your data is never sent to a server.
