Free JSON to Go Struct Converter

Convert JSON to Go structs online. Generates exported field names with proper initialisms, json tags, omitempty for optional keys and nested named structs.

  • No upload, 100% private
  • Instant, in your browser
  • 100% free, no signup
Loading tool…
Read the complete guideHow to Unmarshal JSON Into Go Structs: Tags, omitempty, Pointers →

About the JSON to Go Struct tool

Calling a REST API from Go means declaring structs that mirror the JSON response, then adding a json tag to every field so encoding/json knows how to map it. For a large payload that is a lot of careful typing. This JSON to Go converter reads a sample response and writes the structs for you.

Each JSON object becomes a named struct and nested objects become their own types, named after the key (orders becomes Order). Field names are exported PascalCase with Go's usual initialisms, so user_id becomes UserID and avatarUrl becomes AvatarURL. Integers are typed int64, decimals float64, and arrays become slices. When your sample is an array of objects, all items are merged, so a key that only appears in some items is marked with omitempty. Values that are null or mixed become any, and you can turn on pointers for nullable fields.

The type inference is the same engine used by our JSON to TypeScript tool, and it runs entirely in your browser.

How to use JSON to Go Struct

  1. Paste a JSON response into “JSON sample”, open a .json file or click “Load sample”.
  2. Set the “Root type name” and the Go “Package”.
  3. Toggle “omitempty on optional fields” and “Pointers for nullable fields”.
  4. Review the generated structs in the output pane.
  5. Click “Copy” or “Download” to save a .go file.

Features

Idiomatic field names

Exported PascalCase names with ID, URL, API, HTTP and similar initialisms upper-cased.

Exact json tags

Every field keeps its original JSON key in the tag, including keys with dashes.

Merged array samples

All objects in an array are combined so optional keys are detected.

Shared nested types

Identical object shapes are declared once and reused.

Aligned output

Fields, types and tags are column-aligned like gofmt would print them.

When to use it

  • Model a third-party API response before writing a Go client.
  • Create config structs from an existing JSON settings file.
  • Decode webhook payloads from Stripe, GitHub or Slack in a Go service.
  • Speed up writing tests that unmarshal JSON fixtures.
  • Port a JavaScript service to Go with the same data shapes.

Frequently asked questions

Why is a field typed any?

The sample only had null for that key, or had different kinds of value such as a string in one item and a number in another. Replace any with the right type once you know it.

Why int64 and float64?

They are the safe defaults. A key is float64 if any sample value has a decimal part. Change them to int or float32 if your data allows.

When is omitempty added?

With the option on, it is added to keys missing from some objects in the sample and to keys that were null.

Does it parse dates into time.Time?

No. Date strings stay string, because time.Time requires a specific RFC 3339 format that not every API follows.

Is my JSON sent anywhere?

No. The structs are generated in your browser.

Related tools