World’s largest virtual agentic engineering & quality conference
Paste JSON and get Go structs with json tags in real time. All conversion happens in your browser, and nothing is uploaded.
A JSON to Go struct converter is a code generation tool that reads a JSON document and produces matching Go struct type definitions. It infers a Go type for every value, creates nested structs for nested objects, and attaches json struct tags so the encoding/json package can decode the data and encode it back.
JSON is defined by RFC 8259, and Go reads and writes it through the standard encoding/json package. TestMu AI built this converter for backend developers and QA engineers who turn API payloads into typed Go models for services, CLIs, and test suites.
Working across languages? The same payload converts to TypeScript interfaces with the JSON to TypeScript tool and to Kotlin classes with the JSON to Kotlin tool.
The converter parses your JSON with the browser's native JSON parser and walks the result recursively. Each key is capitalized into an exported field, nested objects become named structs, and an array of objects becomes a slice of a generated element type (an orders array produces []Order). Objects with identical field sets are deduplicated into a single struct definition.
Every field carries a json tag with the original key, so the generated code round trips your payload without renaming anything. All processing happens in your browser. Your JSON is never uploaded, stored, or sent to a server.
| JSON value | Generated Go type |
|---|---|
| String | string |
| Whole number | int |
| Decimal number | float64 |
| true or false | bool |
| Object | Named nested struct |
| Array of objects | Slice of a generated struct, for example []Order |
| Array of strings or numbers | Typed slice, for example []string |
| Empty array | []interface{} |
| null | Cannot be inferred. Edit the generated field to a pointer, any, or json.RawMessage |
Try this: paste the JSON below and compare your output.
{"name":"Asha","active":true,"orders":[{"id":1,"total":250.75}]}The converter returns these two structs:
type Root struct {
Name string `json:"name"`
Active bool `json:"active"`
Orders []Order `json:"orders"`
}
type Order struct {
Id int `json:"id"`
Total float64 `json:"total"`
}Decoding, also called unmarshaling, turns JSON bytes into a typed Go value. Pass json.Unmarshal a byte slice and a pointer to a variable of the generated struct type.
package main
import (
"encoding/json"
"fmt"
)
type Order struct {
Id int `json:"id"`
Total float64 `json:"total"`
}
type Root struct {
Name string `json:"name"`
Active bool `json:"active"`
Orders []Order `json:"orders"`
}
func main() {
data := []byte(`{"name":"Asha","active":true,"orders":[{"id":1,"total":250.75}]}`)
var root Root
if err := json.Unmarshal(data, &root); err != nil {
fmt.Println("decode failed:", err)
return
}
fmt.Println(root.Orders[0].Total) // 250.75
}When the JSON comes from an io.Reader, such as an HTTP response body or a file, wrap the reader with json.NewDecoder and call Decode, for example json.NewDecoder(resp.Body).Decode(&root). If you decode into any instead of a struct, every JSON number arrives as float64, which is one more reason typed structs with int and float64 fields are the safer choice.
Encoding, also called marshaling, is the reverse trip. json.Marshal returns the JSON encoding of the value you pass in, and json.MarshalIndent formats the same output with indentation for logs and config files.
root := Root{Name: "Asha", Active: true, Orders: []Order{{Id: 1, Total: 250.75}}}
out, err := json.Marshal(root)
if err != nil {
fmt.Println("encode failed:", err)
return
}
fmt.Println(string(out))
// {"name":"Asha","active":true,"orders":[{"id":1,"total":250.75}]}
pretty, _ := json.MarshalIndent(root, "", " ")
fmt.Println(string(pretty))Only exported fields appear in the result, and the json tags supply the output keys. That is why every struct this converter generates uses capitalized field names with the original JSON key preserved in the tag.
A JSON struct usually refers to a Go struct type that mirrors the shape of a JSON document. Each JSON key maps to an exported Go field with a json struct tag, so the encoding/json package can decode JSON values into typed Go data and encode them back.
Declare a struct with the type keyword, a name, and typed fields, for example: type User struct { Name string }. To generate structs from JSON automatically, paste a sample payload into this converter and copy the produced definitions together with their json tags.
Call json.Unmarshal with a byte slice and a pointer to your struct: err := json.Unmarshal(data, &user). For JSON arriving from an io.Reader, such as an HTTP response body, use json.NewDecoder(resp.Body).Decode(&user). Both functions come from the standard encoding/json package.
Pass the struct value to json.Marshal, which returns the JSON encoding as a byte slice: out, err := json.Marshal(user). For pretty printed output, call json.MarshalIndent with a prefix and an indent string. Only exported fields, those starting with an uppercase letter, appear in the result.
The first letter of every JSON key is capitalized so the generated field is exported and visible to the encoding/json package. Keys should already be valid Go identifiers; the original key is preserved in the json struct tag, so decoding and encoding still match your source JSON exactly.
Yes. The converter names the top level type Root and derives nested struct names from your JSON keys. After copying the output, rename any type in your editor. The json struct tags keep the field to key mapping intact, so renaming types never breaks decoding.
Yes. All processing happens in your browser using JavaScript. Your JSON is never uploaded, stored, or sent to a server, which makes the tool safe for API responses that contain credentials, tokens, or customer data you cannot share outside your machine.
Structs generated from standard JSON payloads use plain Go types and json struct tags that work with every supported Go release. Two extras mentioned on this page have version floors: the any alias requires Go 1.18 or later, and the omitzero tag option requires Go 1.24 or later.
Paste your next API payload above and copy the generated Go structs in seconds. When those models feed automated API suites, run them at scale on HyperExecute, TestMu AI's test orchestration cloud, and generate matching Java models with the JSON to POJO converter.
Did you find this page helpful?
Leverage the power of the Chromium-based engine and take your responsive testing to the next level.
Try for free