Skip to content

JSON to Go Struct

Generate Go structs with json tags from a sample payload.

Field names follow Go's initialism rules, so user_id becomes UserID rather than UserId.

Quick Tool Overview

The JSON to Go Struct converter writes gofmt-aligned structs with json tags, exported field names that follow Go's initialism rules, and pointer types wherever a field can be absent or null.

What it does
Generates Go structs with json tags from a sample
You give it
A JSON payload, ideally an array of records
You get back
Aligned struct declarations ready for encoding/json
Best for
Unmarshalling a third-party API without hand-writing types
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the JSON to Go Struct

Go needs a struct before it can unmarshal anything, and writing one by hand for a large response is tedious. Paste the JSON and get the structs, with the field names exported, the json tags carrying the original keys, and the declarations aligned the way gofmt would leave them.

The naming follows Go convention rather than a naive capitalisation: user_id becomes UserID, api_url becomes APIURL, and the other initialisms the style guide lists are uppercased too. Fields that are absent from some records or that appear as null are declared as pointers, which is how Go distinguishes a missing value from a zero one. There is an omitempty option for the structs you marshal back out.

Key features of the JSON to Go Struct

Go naming, not naive capitalisation

user_id becomes UserID and api_url becomes APIURL, matching the style guide that linters such as golint enforce.

Pointers for optional fields

A *int64 that is nil means the key was absent; a plain int64 of 0 could mean either. The distinction is preserved.

gofmt alignment

Field names, types and tags are padded into columns exactly as gofmt would leave them, so the paste needs no reformatting.

omitempty when you need it

Add the tag option in one click for structs that get marshalled back out and should omit their zero values.

Safe numeric widths

Numbers are typed int64 and float64, because JSON routinely carries values beyond the 32-bit range.

How to use the JSON to Go Struct

  1. 1

    Paste the JSON

    An array of records produces better optional-field detection than a single object.

  2. 2

    Name the root struct

    Nested structs are named from their keys automatically.

  3. 3

    Choose the tag options

    Add omitempty when the struct will be marshalled back to JSON.

  4. 4

    Copy into your package

    Paste the result into a .go file — the declarations are already aligned.

Frequently asked questions

Because Go cannot otherwise tell an absent field from a zero value. A *int64 that is nil means the key was missing; an int64 that is 0 could mean either.

Reviews of the JSON to Go Struct

What people who use the JSON to Go Struct think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the JSON to Go Struct. It takes half a minute and no account.

Write the first review

More developer tools