JSON to Go Struct Generator
Paste any JSON and generate Go structs with json tags instantly in your browser — no signup, nothing uploaded.
JSON Input
Go Structs
How to Generate Go Structs from JSON
Paste your JSON
Copy a JSON response, config file, or any JSON object and paste it into the input panel. Minified or pretty-printed JSON both work.
Set a struct name
Enter a name for the top-level struct. Defaults to Root. Use something descriptive like User, ApiResponse, or WebhookPayload.
Generate and copy
Click Generate Structs. Copy the output or download it as a .go file ready to use with encoding/json.
What Are Go Structs and JSON Tags?
A Go struct is a composite type that groups named fields. When working with JSON in Go, the standard library's encoding/json package uses struct field tags to control how each field is serialized and deserialized.
The json tag on each field — written as `json:"fieldName"` — maps the Go field name to the JSON key. Without this tag, Go uses the field name exactly, which breaks for camelCase JSON keys or keys with special characters.
Example
type User struct {
Id int `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Address Address `json:"address"`
}
type Address struct {
Street string `json:"street"`
City string `json:"city"`
}How the Generator Works
Type inference
JSON strings map to string, integers to int, decimals to float64, booleans to bool, and null to interface{}.
Nested structs
Each nested object generates its own named struct. The name is derived from the JSON key in PascalCase. Output is ordered top-down so the root struct appears first, followed by referenced structs.
Arrays of objects
When an array contains objects, all elements are merged into a single struct. Keys present in only some elements get pointer types (*string, *int, etc.) and omitempty in their json tag.
Mixed-type arrays
Arrays containing multiple different value types fall back to []interface{} since Go cannot express a union type natively.
Use Cases
API Response Parsing
Generate a struct from a logged API response to type your HTTP client. Use encoding/json to decode the response body directly into the struct.
Config File Loading
Turn a JSON config file into a Go struct so your config loader is fully typed. Compile-time checks catch missing or wrong-type fields before deployment.
Database Document Mapping
Convert MongoDB document samples or DynamoDB item responses into Go structs for your data access layer — no manual field-by-field transcription.
Third-Party Webhook Payloads
Paste a webhook payload from GitHub, Stripe, or any service to generate the struct you need to unmarshal incoming events in your handler.
Microservice Message Schemas
Generate Go structs for Kafka, NATS, or gRPC JSON message payloads to ensure consistent serialization between producers and consumers.
gRPC/OpenAPI Integration
Supplement generated protobuf or OpenAPI code by quickly producing structs for JSON payloads in intermediate transformation steps.
Generated Struct Examples
Simple flat object
JSON input
{
"id": 42,
"name": "Alice",
"active": true,
"score": 9.5
}Go output
type Root struct {
Id int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Score float64 `json:"score"`
}Array with optional fields
JSON input
[
{"id":1,"name":"Alice","role":"admin"},
{"id":2,"name":"Bob"}
]Go output
// Top-level JSON is an array: []Root
type Root struct {
Id int `json:"id"`
Name string `json:"name"`
Role *string `json:"role,omitempty"`
}Nested structs
JSON input
{
"user": {
"id": 1,
"address": {"city":"NY"}
}
}Go output
type Root struct {
User User `json:"user"`
}
type User struct {
Id int `json:"id"`
Address Address `json:"address"`
}
type Address struct {
City string `json:"city"`
}Limitations to Be Aware Of
- ⚠Go acronym conventions: Go convention uses uppercase acronyms —
ID,URL,HTTP. The generator uses simple PascalCase (Id,Url). Rename acronym fields manually after generating. - ⚠Null becomes interface{}: A JSON null cannot reveal its real type. Change to a pointer type (
*string) or concrete type if you know it. - ⚠Single sample inference: Type inference is based only on the JSON you provide. If an API sometimes returns a different type for a field, adjust the generated struct manually.
- ⚠No package declaration: The output does not include a
packagestatement. Addpackage mainor your package name before using the file.
Frequently Asked Questions
How do I convert JSON to a Go struct?
Paste your JSON into the input box, optionally set a root struct name, and click Generate Structs. The tool produces Go struct definitions with json tags that match the exact shape of your JSON, ready to use with encoding/json.
What are json tags in Go structs?
JSON tags are struct field annotations that control how encoding/json marshals and unmarshals a struct. For example, `json:"firstName"` maps the Go field FirstName to the JSON key "firstName". Without tags, Go uses the exact field name which may not match your JSON keys.
How are optional fields represented?
Fields that appear in only some elements of a JSON array are marked optional. The generator uses pointer types (*string, *int, etc.) and adds omitempty to the json tag. A nil pointer means the field was absent during unmarshaling.
How are null JSON values handled?
A JSON field whose value is null is typed as interface{} because the actual type cannot be inferred from null alone. If you know the real type, change it manually — for example, to *string for a nullable string field.
Does the generator handle nested objects?
Yes. Each nested object becomes a separate named Go struct. The name is derived from the JSON key using PascalCase — an "address" field produces an Address struct referenced by the parent struct.
Is my JSON sent to a server?
No. All struct generation runs entirely in your browser using JavaScript. Your JSON data never leaves your device and is not stored anywhere.
How do I use the generated structs to parse JSON in Go?
Import "encoding/json" and call json.Unmarshal(data, &myStruct) where data is a []byte of your JSON. For HTTP responses, use json.NewDecoder(resp.Body).Decode(&myStruct). The json tags ensure keys map correctly.
From the Blog
View all →5 JSON Formatter Tips for Faster API Debugging
Practical JSON formatting habits that reduce debugging time when working with API responses and logs.
How to Format JSON in JavaScript
A practical guide to formatting, validating, and safely pretty-printing JSON in modern JavaScript apps.
JSON vs XML — Which Should You Use?
A practical comparison of JSON and XML for APIs, integration workflows, and long-term maintainability.
Top 5 Free Online JSON Formatters Compared
A feature-by-feature comparison of five popular free JSON formatters, with a practical ranking for developer workflows.
