Productivity and Utilities

JSON to Go Struct Generator

Paste a JSON example to get the Go struct types.

    Numbers without a decimal point or exponent become int, other numbers become float64. A field missing from some objects in a list gets omitempty. A field that is only ever null becomes interface{}. Names are exported, with common initialisms such as ID and URL in capitals. Everything runs in your browser and nothing is uploaded.

    Next step

    How to use the json to go struct generator

    1. Paste a JSON example.
    2. Enter the name of the main type, and choose whether to add omitempty to every field.
    3. Choose whether fields that are sometimes null become pointers.
    4. Copy the Go code or download it as a file.

    Formula

    string, true and false, and numbers become string, bool and int or float64

    A number without a decimal point or exponent is an int, and any other number is a float64

    Lists become slices. Objects in a list are merged, and a field missing from some of them gets omitempty

    Names are exported, with common initialisms such as ID and URL in capitals, and the key stays in the json tag

    One example cannot show every shape a field can take, so check the types against more samples.

    A user record with a list of orders

    The sample has an id, a name, an email that is null, a flag, a score of 98.5, a home_url, a list of tags, an address object and a list of orders. The id becomes ID int, home_url becomes HomeURL string, is_admin becomes IsAdmin bool and score becomes Score float64. The email is only ever null, so it is an interface{}.

    The orders list has two objects, and only the second has a note, so the Orders type gets Note string with the tag json:"note,omitempty". The totals 25.5 and 30 merge to float64. Three types come out: Root, Address and Orders.

    What the generator decides for you

    Writing Go structs for a large JSON response by hand is slow and full of small mistakes. The generator reads the example, works out the type of each field and writes the structs in the same layout gofmt would. The code was checked by running it through gofmt, go vet and a Go program that reads each sample into the type and writes it back.

    A field that holds null in some places and a string in others needs a pointer, because a plain string cannot be null. With the pointer option on, such fields get *string, *int and so on. A field that holds null and nothing else has no type to infer and becomes interface{}.

    Limits and next steps

    The omitempty option leaves out zero values and null when writing JSON, so an explicit null in the source disappears on the way back. Numbers written as 1.0 are floats, and a field that holds both integers and decimals becomes float64. For TypeScript use the JSON to TypeScript tool, for a schema the JSON Schema Generator, to check the sample the JSON Formatter and Validator, and to make it stable for hashing the JSON Canonicalizer.

    Assumptions and limits

    • The JSON example is valid and shows the data you will read.
    • Objects in one list share a type, and their fields are merged.
    • The sample is an example. Use a real response from your own service.
    • Everything runs in your browser and nothing is uploaded.

    Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

    Frequently asked questions

    Why is a field an interface{}?

    Either it is only ever null in the sample or its values have mixed types, so there is no single Go type to use.

    Why is a number a float64 when I typed 1.0?

    Go cannot read 1.0 into an int, so any number written with a decimal point or exponent becomes a float64.

    What does omitempty do?

    When writing JSON, the field is left out if it has its zero value, such as an empty string, 0 or a nil pointer.

    How are names with dashes or digits handled?

    Words are split at anything that is not a letter or digit, then joined with capitals. A name that starts with a digit gets an X in front.