JSON to Go Struct Converter

Paste JSON and get idiomatic Go structs with json tags for encoding/json.

100% Client-Side Processing — your data never leaves this browser. Works offline. How it works

0 lines • 0 bytes Ready
Tip: drop a file anywhere on the editor
Input
Paste, type or drop a file
1
Result
Updates as you type
// Output will appear here…
About this tool

How the JSON to Go Struct works

Generate Go structs with json tags from JSON. Nested objects become named types, optional fields become pointers with omitempty, and IDs follow Go naming.

How to use the JSON to Go Struct

  1. Paste a JSON object or array (an API response works well).
  2. Set the root struct name.
  3. Copy the structs into your Go package.

JSON to Go Struct example

Input
{"id":7,"user_name":"aarav","tags":["a"],"address":{"city":"Pune"}}
Result
type User struct {
	ID       int64    `json:"id"`
	UserName string   `json:"user_name"`
	Tags     []string `json:"tags"`
	Address  Address  `json:"address"`
}

type Address struct {
	City string `json:"city"`
}

When to use it

  • Typing third-party API responses in Go services.
  • Writing request and response structs for handlers.
  • Decoding JSON config files.

Tip: Paste several array items rather than one: optional fields can only be detected when some items lack them.

Named nested types

Nested objects become their own structs (Address, Order) instead of anonymous structs.

Idiomatic names

Fields are exported with Go initialisms: user_id becomes UserID, api_url becomes APIURL.

Optional fields

Fields missing from some array items, or null, become pointers with omitempty.

Smart types

int64, float64, bool, string, time.Time for RFC 3339 timestamps, and slices for arrays.

FAQ

Common questions

How are arrays of objects typed?

Items are merged into one struct named after the singular key (orders → Order); fields missing from some items become optional.

Why is a field a pointer?

It was null or missing in at least one example, so a pointer lets you tell "absent" from the zero value.

Which Go version is needed?

The output uses any for unknown values, which needs Go 1.18 or later.

Is my JSON uploaded?

No, the code is generated in your browser.