Skip to content
AZ Tools

JSON to Go Struct Converter

Paste a sample JSON payload and get a matching Go type definition instantly — conversion runs live as you type, entirely in your browser. Object keys become exported PascalCase field names so encoding/json can marshal them, and every field carries a json:"…" tag holding the original key, so a round trip through the standard library reproduces the JSON you started from. Whole numbers map to int64, decimals to float64, and nested objects become inline anonymous structs that mirror the payload's shape. Because types are inferred from a single sample, treat the output as a strong first draft: a field that happens to be 42 becomes int64 even if the API can also return 41.5, null and empty arrays come out as interface{} since the sample reveals no element type, and a slice's type is taken from its first element only. Review the result, tighten what you know better, and add ,omitempty or pointers for optional fields. Your input never leaves your device and is kept in localStorage so it survives a reload.

Go struct

How to use

  1. Paste or type a sample of your JSON into the input box — conversion runs live, there's no button to press.
  2. Name the root struct if you like (defaults to AutoGenerated); the name is normalized to an exported PascalCase identifier.
  3. Copy the generated definition with the Copy button and paste it into your Go file.
  4. Review the inferred types: widen numbers that can be fractional, replace interface{} placeholders, and add ,omitempty where fields are optional.

Frequently asked questions

How are numbers typed?
Whole numbers become int64 and anything with a fractional part becomes float64. That's inference from one sample — if a field can ever be fractional, change it to float64 yourself, and if you need exact decimal handling, consider json.Number instead.
What happens with null or empty arrays?
null values map to interface{} and empty arrays to []interface{}, because the sample carries no type information for them. Replace these once you know the real type — a field that can be null is often best expressed as a pointer in Go.
How are field names and json tags chosen?
Keys are split on non-alphanumeric characters and PascalCased into exported identifiers (user_id becomes UserId), because encoding/json can only see exported fields. The original key is preserved verbatim in the json tag, so marshaling reproduces your input keys exactly.
Are nested objects generated as separate named types?
No — they're emitted as inline anonymous structs, which keeps the output a single self-contained declaration you can paste anywhere. If a shape repeats in several places, extract it into a named type by hand. Also note an array's element type is inferred from its first element only, so mixed-type arrays won't be flagged.
Is my JSON sent anywhere or stored?
It never leaves the browser — parsing and generation are pure client-side JavaScript. For convenience the input and root name are saved to your browser's localStorage so they survive a reload; clear the input after pasting anything sensitive on a shared machine.

Related tools