JSON to Go
Convert JSON objects and arrays into Go structs with inferred types, nested structs, and JSON tags.
JSON Input
Go Output
Go structs
package models
// Generated from JSON.
// Review interface{} fields and inferred types before using this model.
type Profile struct {
Country string `json:country`
Timezone interface{} `json:timezone`
}
type ProjectsItem struct {
Name string `json:name`
Stars int `json:stars`
}
type ProjectsItem2 struct {
Name string `json:name`
Stars int `json:stars`
}
type GeneratedModel struct {
ID int `json:id`
Name string `json:name`
Email string `json:email`
IsActive bool `json:isActive`
Roles []string `json:roles`
Profile Profile `json:profile`
Projects []interface{} `json:projects`
}
Generation notes
- • Nested JSON objects become separate Go structs.
- • JSON arrays become Go slices with inferred element types.
- • Arrays of objects are analyzed together so fields from every sample are preserved.
- • JSON field names are preserved using struct tags.
- • The pointer option applies to nested struct fields.
- • Null-only fields and mixed-type arrays may require manual type adjustments.
- • Go zero values are used for missing fields unless you use pointers or custom unmarshalling.
How to use JSON to Go
- 1Paste a valid JSON object or array.
- 2Set the root struct name and pointer preference.
- 3Copy or download the generated Go code.