JSON to Go Struct
Infer Go structs from JSON.
About this tool
Paste a JSON object and get a Go struct with json struct tags, ready for encoding/json. Strings, integers, floats, booleans and slices are mapped. Nested objects fall back to map[string]interface{}.
How to use
How it works
Each key becomes an exported field, made by converted to PascalCase (common initialisms like ID and URL are upper-cased), with a json tag that holds the original key. Types are string, int, float64, bool and []T (from the merged array items); anything nested is map[string]interface{}. The struct is named Root.
Worked example
A scored item
- Input
- {"id":1,"name":"Ada","score":9.5,"tags":["a"],"active":true}
- Output
- type Root struct { ID int `json:"id"` Name string `json:"name"` Score float64 `json:"score"` Tags []string `json:"tags"` Active bool `json:"active"` }
- Walkthrough
- Field names are PascalCase and common initialisms are upper-cased, so id becomes ID. Run gofmt to align the columns.
Limitations
- No nested structs: nested objects use map[string]interface{}.
- Field names are PascalCase with common initialisms upper-cased (user_id becomes UserID).
- No omitempty, pointers or time.Time are generated.
Questions
How do I convert JSON to a Go struct?
Does it add json tags?
Why is the field called Id instead of ID?
How are nested objects handled?
Features
- json tags
- int vs float64 detection
- Slices from arrays
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
Learn JSON - Full Crash Course for Beginners
freeCodeCamp.org
Solid JSON syntax and nesting basics for formatter and validator tools.
Watch on YouTubeWhat Is A RESTful API?
Traversy Media
Most APIs exchange JSON—context for pretty-print and schema checks.
Watch on YouTube
- RFC 8259 — The JavaScript Object Notation
IETF
The standards text behind modern JSON interoperability rules.
- Introducing JSON
json.org
Canonical JSON grammar—handy when a formatter rejects a trailing comma.