Convert JSON to Go Struct
online, free & instant
Paste your JSON and get Go struct definitions with exported fields, json tags, and proper type mapping. Works entirely in your browser — no upload, no account, no waiting.
Open JSON to Go ConverterFrom JSON to Go struct in seconds
No account. No upload. No nonsense.
100% Private
Your JSON never leaves your device. There is no server receiving your data.
Instant Output
Conversion happens as you type. No round-trips to a backend, no latency.
Idiomatic Go
Exported fields, PascalCase names, proper json tags — ready for encoding/json.
Related JSON tools
Common questions answered
How does the converter map JSON types to Go types?
JSON strings map to Go string, numbers to float64 (or int if they have no decimal), booleans to bool, null to a pointer type, arrays to slices, and nested objects to nested structs. Each field gets a json tag matching the original key name.
Is the JSON to Go struct converter free?
Yes, completely free with no account or signup required.
Does it generate json tags for encoding/json?
Yes. Every field includes a json struct tag like `json:"field_name"` so it works directly with Go's encoding/json package for marshaling and unmarshaling.
How are nested JSON objects handled?
Nested objects become separate Go struct types. The parent struct references the child by its generated type name, keeping the code clean and idiomatic Go.
Is my data sent to a server?
No. All conversion runs entirely in your browser using JavaScript. Your JSON is never uploaded or transmitted.
Converting JSON to Go structs
Go requires explicit struct definitions to unmarshal JSON data. Each field needs a name, type, and json:"fieldname" tag. Writing these by hand is tedious for deeply nested JSON. This tool generates complete Go struct definitions with proper field names (PascalCase), types, and JSON tags automatically.
The converter follows Go conventions: field names are PascalCase (exported), types are inferred (string, int64, float64, bool), and nested objects become separate struct types. Arrays are typed as slices. When a field could be absent, the type uses a pointer (*string) to distinguish zero values from missing fields.
{
"name": "Alice",
"age": 30,
"address": {
"city": "Portland",
"zip": "97201"
}
}
type Root struct {
Name string `json:"name"`
Age int64 `json:"age"`
Address Address `json:"address"`
}
type Address struct {
City string `json:"city"`
Zip string `json:"zip"`
}
Get the most out of this tool
- Go struct tags use json:"fieldName" to map struct fields to JSON keys — generated automatically by this tool.
- Review generated structs for pointer types: *string allows distinguishing between missing and empty string values.
- Nested JSON objects generate separate struct types that you may want to rename for clarity in your codebase.
Ready to convert your JSON to Go structs?
Free forever. No signup. Works offline.
Convert JSON to Go nowGo struct generation explained
Go's type system is strict and statically typed, which means you must define exact struct types before you can unmarshal JSON into them using the encoding/json package. When working with external APIs, you receive JSON responses whose schema must be translated into Go types. Doing this by hand is repetitive, error-prone, and slow — especially for payloads with dozens of fields or multiple nesting levels.
The converter follows Go naming conventions precisely. JSON keys like "first_name" or "firstName" both become FirstName in Go — snake_case is converted to PascalCase, and camelCase is capitalized at the first letter. This matches Go's requirement that exported identifiers start with an uppercase letter, making the fields accessible to the encoding/json package and to code in other packages.
Type inference is a critical step. JSON strings always map to Go's string type. JSON numbers with no decimal point map to int64 for large number safety. Numbers with decimals become float64. JSON booleans map to bool. The null value in JSON is tricky — Go has no null, so the converter uses pointer types (*string, *int64, etc.) which can hold a nil value, distinguishing between a missing field and a zero-value field.
JSON arrays require the converter to determine the element type. Homogeneous arrays (all strings, all numbers) produce clean slice types like []string or []float64. Arrays containing JSON objects produce []TypeName where TypeName is a newly generated struct. Mixed arrays containing different primitive types fall back to []interface{}, which accepts any JSON value at the cost of type safety.
Nested JSON objects are the most important conversion case for real APIs. Each nested object becomes its own named struct type, and the parent struct references it by name. This matches idiomatic Go — deeply nested inline types are hard to read and reuse. The generated type names are derived from the JSON key name, capitalized. You will often want to review and rename them to better reflect your domain model.
Once you have generated structs, you can unmarshal a live API response with just a few lines: json.NewDecoder(resp.Body).Decode(&result). If the struct fields have omitempty tags, missing optional fields will not cause errors. You can add custom validation logic, implement the json.Unmarshaler interface for special types like time.Time, or add additional struct tags for XML or database ORM compatibility.
Go developers working with GraphQL APIs, gRPC-gateway JSON, OpenAPI-generated schemas, or webhook payloads all regularly need to convert incoming JSON shapes to Go structs. The alternative — using map[string]interface{} — loses type information entirely and requires type assertions at every field access, which is both verbose and fragile. Generated structs are always the better long-term approach.
When developers use this tool
Getting the most from generated Go structs
- Review pointer types carefully: The converter uses pointers for nullable JSON fields, but if your API always sends those fields, you can remove the pointer for simpler code. Only keep pointers where the field genuinely may be absent or null.
- Add omitempty where needed: If you are also marshaling structs back to JSON and want to omit zero-value fields, add ,omitempty to json tags. The generated structs include the tag structure needed — just append the option.
- Rename generated types: Names like Address or Items derived from JSON keys are generic. Rename them to match your domain model — UserAddress, OrderItems — so your codebase is self-documenting.
- Handle time.Time fields: JSON timestamps are usually strings in RFC 3339 format. The converter produces string for these. Replace string with time.Time and implement custom UnmarshalJSON if your API uses non-standard date formats.
- Use go generate for long-term maintenance: For APIs that change frequently, consider storing the sample JSON in your repo and using go:generate comments to re-run the converter when the schema changes.
Additional frequently asked questions
Can I generate structs for JSON arrays at the top level?
Yes. If your JSON starts with a [ array bracket, the converter wraps it appropriately and generates the element struct type. The result is a Go slice type like []Item where Item is the generated struct for the array element shape.
Does the tool handle JSON with inconsistent types across array elements?
Arrays with mixed types (e.g., sometimes a string, sometimes a number) are represented as []interface{} in the output. This is the safest representation in Go, though it loses type safety. Homogeneous arrays always produce typed slices like []string or []float64.
How should I handle date and time fields in generated structs?
The converter produces string for any JSON string field, including timestamps. After generating the struct, manually change the type to time.Time for date fields and use json.Unmarshal with a custom type that implements UnmarshalJSON to parse the format your API uses.
Can I add struct tags for database ORMs like GORM?
The converter only generates json tags. After pasting the output into your editor, you can add db, yaml, xml, or gorm tags to each field. Most Go editors with Go language server support offer multi-cursor editing to add tags efficiently across many fields at once.