Shard Tools

JSON to Go Struct

Generate Go structs from a JSON sample in your browser, complete with json struct tags.

Maintained by Roshan.

Use JSON to Go Struct

Converts json sample to go struct in this tab, with nothing sent anywhere.

Runs entirely on your deviceThe conversion happens in this browser tab. Nothing you type is uploaded, logged or stored, which is worth knowing for anything you would not paste into a search box.

Explore generators

Find related browser-local tools for nearby tasks without starting another search.

Browse all generators

About JSON to Go Struct

Go's static typing means consuming a JSON API starts with declaring a struct that matches it, and doing that by hand is fiddly - every field needs both an exported Go name and a json tag mapping it back to the original key. Generating the struct from a sample handles both at once: paste the JSON, get the struct with its tags already written. This infers the shape recursively, giving each nested object its own struct, and applies Go's conventions automatically - exported PascalCase field names paired with json tags carrying the original lower-case keys, so encoding and decoding round-trip correctly. The result is a working struct you can paste into a Go file and refine, rather than a skeleton you fill in field by field.

Using JSON to Go Struct

  1. The JSON is parsed and its structure inferred recursively.
  2. Each field gets an exported PascalCase Go name and a json tag preserving the original key, so decoding matches the source.
  3. Nested objects become their own named structs, referenced by the parent.
  4. JSON numbers map to float64, the safe default for arbitrary JSON numbers; narrow to int where you know the data.
  5. Arrays become slices of the inferred element type.

Where json to go struct helps

Consuming a JSON API in Go

Paste a sample response and get the struct with json tags ready for encoding/json to decode into.

Modelling a config file

Generate the struct from an example config, then narrow numeric types and mark optional fields.

Before you use the result

Questions about JSON to Go Struct

Are json tags included?

Yes. Every field carries a json tag with the original key, so decoding round-trips correctly.

Why is every number a float64?

JSON has one number type. float64 is the safe default; narrow to int where you know the value is whole.

Does it handle nested objects?

Yes. Each becomes its own named struct referenced by the parent.

What about optional fields?

Go uses zero values for missing fields. Add pointer types yourself where a field is genuinely optional.

Related tools

JSON to TypeScript

Generate TypeScript interfaces from a JSON sample in your browser. Nested objects become their own interfaces.

JSON to Rust Struct

Generate Rust structs from a JSON sample in your browser, deriving Serialize and Deserialize.