Skip to content
XUtilHub

JSON to Go Struct Converter

Convert JSON to Go structs with json tags, idiomatic initialisms (ID, URL, API), pointers for nullable values and omitempty for optional fields. gofmt-aligned.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Code

About the JSON to Go

Generate Go struct definitions with json tags from any JSON sample. Field names follow Go conventions, including initialisms like ID and URL, and the output is aligned like gofmt.

Key features

  • Go structs with json:"…" tags for every field
  • Idiomatic names with initialisms: ID, URL, API, HTTP
  • Pointers (*T) for nullable values
  • omitempty for fields missing from some items
  • Columns aligned like gofmt
  • Custom package name

Go structs from JSON

Decoding JSON in Go means writing structs with exported fields and json tags. Doing that by hand for a large API response is tedious. Paste the JSON and get ready-to-use structs that follow Go conventions.

Example

[
  { "user_id": 7, "avatar_url": "https://…", "nickname": "ada", "roles": ["admin"] },
  { "user_id": 8, "avatar_url": "https://…", "nickname": null, "roles": [] }
]
type Root struct {
	UserID    int64    `json:"user_id"`
	AvatarURL string   `json:"avatar_url"`
	Nickname  *string  `json:"nickname"`
	Roles     []string `json:"roles"`
}
var items RootList // the JSON is an array, so a RootList []Root type is generated too
if err := json.Unmarshal(data, &items); err != nil {
	return err
}

Type mapping

JSONGo
"text"string
42int64
3.14float64
truebool
[...][]T
{...}named struct
null*T
missing in some items*T + ,omitempty
unknownany

Tips

  • Time values: change ISO date strings to time.Time; encoding/json parses RFC 3339 automatically.
  • Large numbers: use json.Number if you need exact precision beyond float64 for decimals.
  • Strict decoding: decoder.DisallowUnknownFields() catches unexpected keys.

Generate the client side with JSON to TypeScript, or another systems language with JSON to Rust.

How to use the JSON to Go

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The Go appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

Why are some fields pointers?

A pointer lets a field be nil, which is how Go represents a JSON null or a missing value. Non-pointer fields fall back to the zero value ("", 0, false) instead.

Why int64 instead of int?

int64 has a fixed size on every platform, which avoids surprises with large IDs. Change to int if you prefer.

Why is my field named ID and not Id?

Go's style guide (and linters like staticcheck) expect initialisms to keep consistent case: ID, URL, HTTP, API. The json tag still maps to your original key.

What does 'any' mean?

The value's type couldn't be inferred (null, mixed or empty). any is Go's empty interface; replace it with a concrete type when you know it.

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools