My Tools Garage

JSON to Go Struct

Generate Go structs from JSON instantly.

in-browser

How to use

  1. 1 Paste a JSON object into the input box.
  2. 2 Optionally rename the root struct.
  3. 3 Review the generated Go structs with json tags.
  4. 4 Copy the code into your Go project.

About JSON to Go Struct

JSON to Go Struct turns a sample JSON object into idiomatic Go struct definitions, complete with the json struct tags you need to unmarshal real payloads.

Writing these types by hand is tedious and error-prone: you have to match every key, pick the right Go type, and remember to add a back-tick tag for each field.

This tool reads your JSON and does all of that for you in a moment.

Field names are converted to exported PascalCase identifiers while the original key is preserved in the json tag, so AbC mapping is correct even for snake_case or kebab-case keys.

Primitive values are mapped sensibly — strings to string, booleans to bool, whole numbers to int, and decimals to float64 — and null becomes interface{}.

Nested objects are emitted as their own named structs and referenced from the parent, and arrays produce slice types based on their first element, giving you clean, compilable code rather than one giant blob.

You can rename the root struct to match your domain, and copy the result straight into your editor.

As with every My Tools Garage utility, the conversion happens entirely in your browser, so your JSON — which may contain sensitive shapes from internal APIs — is never uploaded or stored anywhere.

FAQ

How are numbers typed?

Whole numbers become int and numbers with a decimal point become float64. Adjust the type by hand if you need int64 or another size.

Does it support nested objects and arrays?

Yes. Nested objects become their own named structs, and arrays produce slice types inferred from the first element.