Skip to content

JSON to Go Structs with json Tags

Open or paste JSON and Go structs with json tags appear at once, ready to copy or download as .go; nothing is uploaded.

Processed on your device. Nothing is uploadedHow to check

Try a sample file:

You can also paste JSON with Ctrl+V (⌘+V on a Mac).

Your file is opened in this browser tab only: it is never uploaded or stored anywhere, and it is gone when you close the tab.

  • JSONView and edit.json

Also works with CSV, TXT, Excel, Word, PDF, Image, and PowerPoint files

Paste text instead

Pasted text stays in this tab and is never sent anywhere.

Writing Go structs for a JSON payload means getting every field name, type and tag right. Open or paste the payload and the page writes them for you: exported field names in Go style, a json:"…" tag that keeps the original key, int64 or float64 depending on the numbers in the sample, slices for arrays, and a separate struct for each nested object. Copy the code into your package or download a .go file, then pass it to json.Unmarshal. The structs are generated in your browser, and the payload never leaves your device.

Why use JSON to Go

  • Private

    Your JSON is read and the structs are written by your own browser; nothing is sent to a server.

  • Tags written for you

    Each field carries a json tag with the exact key from your data, so encoding/json maps it both ways.

  • Works offline

    After you have used it once, it keeps working without an internet connection.

How it works: generate Go structs from JSON

  1. Open or paste a payload

    Paste JSON into the box, drop or choose a .json file, or try a sample.

  2. Read the structs

    The Go code is shown at once, with one struct per kind of object and a json tag on every field.

  3. Copy or download

    Copy the structs into your package or download them as a .go file, then run gofmt as usual.

What the JSON to Go generator handles

  • Field names: keys such as user_id or created-at become exported names such as UserID and CreatedAt, with the original key in the tag.
  • Numbers: int64 when every value seen is whole, float64 when one has a decimal part.
  • Arrays: slices typed by their items, such as []string or []Item; objects in one array merge into one struct.
  • Optional fields: a key that is missing from part of the sample becomes a pointer with omitempty in its tag; one that is null in part of it becomes a pointer.
  • Nested objects: each gets its own named struct.
  • Input from a .json file, a drop, the paste box or a sample, up to 10 MB.

JSON to Go: what it can't do

  • Types come from one sample: a value type the sample never shows is not known.
  • Struct names are taken from the keys that hold the objects; rename them to suit your package.
  • Very large documents may take a few seconds; files up to 10 MB.

JSON to Go structs: questions and answers

Is my file uploaded?
No. The JSON is read and the Go code is generated by your browser, on your device. Pasted text stays in this tab and is never sent anywhere.
Why do some fields have omitempty?
Those keys were missing from some of the objects in the sample, so they are optional. omitempty tells encoding/json to leave the field out when you marshal a struct where it is empty.
Why is an optional field a pointer?
A pointer can be nil, which tells "not sent" apart from a zero value such as 0, false or an empty string. Without it you could not know whether the API sent 0 or nothing.
Why int64 and float64 instead of int?
int64 holds any whole number JSON is likely to carry on every platform, and float64 is what encoding/json uses for decimals. Change them to int or float32 by hand if you prefer.
What happens to keys like "user-id" or "2fa"?
Go field names must be exported identifiers, so the name is rewritten in Go style while the json tag keeps the exact original key. Decoding and encoding still use the real key.
My JSON starts with an array. Does that work?
Yes. The items are merged into one struct and the top-level type is a slice of it, so you unmarshal the whole array in one call.
How do I convert JSON to a Go struct?
Paste a JSON payload into OpenAnyDoc's JSON to Go generator and the structs appear at once, one per kind of object with a json tag on every field. Copy them into your package or download a .go file; the JSON stays in your browser.

Why it's private: your files never leave your browser

Most online viewers upload your file to a server, so a copy of it leaves your device. OpenAnyDoc works the other way round: your browser reads the file and draws it on your screen. Nothing is uploaded, there is no account, and the file is gone from memory when you close the tab, so there is nothing for us to store, see or lose.

How we tell you about new features

Announcements are based on the release date shown to everyone, and nothing is stored on your device or sent anywhere.