API Toolkit

JSON to Go

All tools

Paste a payload and get structs that json.Unmarshal can fill.

How it works

Four simple steps

1

Paste the message

Use one JSON object that reflects the real payload.

2

Structs are generated

Fields get exported names and json tags.

3

Tidy for your package

Rename the package, add omitempty or pointers.

4

Save model.go

Copy the code or download the file.

JSON to Go

About JSON to Go

A Go worker needs to consume events from a queue, and the producer team sent a sample message rather than a schema. Generating structs from that message gets you to a compiling json.Unmarshal call in a minute instead of twenty.

The output starts with package main and declares one struct per JSON object. Field names are converted to exported PascalCase (created_at becomes CreatedAt), and each field has a json tag with the original key, so decoding works without renaming anything in the payload. Integers map to int, other numbers to float64, booleans to bool and strings to string. Arrays become slices typed from their first element, nested objects become their own named structs, and an empty array becomes []interface{}. Copy the result or download it as model.go.

Review the output before committing it. Change package main to your package name. The tags have no omitempty, so add it where you encode structs and want zero values left out. A null in the sample is typed as string; use a pointer such as *string for fields that can be null. Initialisms are not uppercased the Go way, so user_id becomes UserId rather than UserID, which Go linters commonly flag. To make sure the sample is valid first, open the JSON syntax validator, and if the producer publishes a JSON Schema, compare it with what the schema generator infers from the same message.

Struct generation happens locally in the page, which keeps internal event formats on your machine.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

Every whole number is typed int. On 64-bit platforms int is 64 bits wide, but if you build for 32-bit targets or want the size explicit, change it to int64.

As string, because JSON has no date type. Change the field to time.Time if the value is in RFC 3339 format, which encoding/json parses automatically.

Struct names come from keys, and the first struct with a given name wins. A later object under the same key reuses that struct even if its fields differ, so check nested types with common names like data or items.

View more FAQs

Related tools

View all

Webhook HMAC Signer

Sign and verify GitHub, Stripe, and Slack webhook signatures locally.

Open

Webhook Replay Diff Lab

Compare webhook payload timelines, re-check HMAC digests, and spot idempotency gaps locally.

Open

JSONPath Playground

Query JSON with JSONPath and JMESPath-style paths side by side.

Open

GraphQL Studio

Format, validate, and cost-estimate GraphQL documents with cURL export.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools