JSON to Go struct
Turn a JSON payload into Go structs with json tags, pointer fields for nullable values and time.Time for timestamps.
Input
Result
The result will appear here.Before encoding/json can unmarshal a payload you need a struct for it, with Go-style field names and a json tag mapping each one back to the original key. This generates them from a sample using quicktype's Go renderer: stargazers_count becomes StargazersCount with the tag json:"stargazers_count", nested objects become their own named structs, and a field that is sometimes null becomes a pointer so that null and the zero value stay distinguishable. The output starts with a package clause and the imports it uses, so it is a complete Go file; change package main to your own package name when you add it to a project.
How it works
- Field names follow Go's initialism convention, so id becomes ID and html_url becomes HTMLURL, the way linters expect.
- Numbers that are whole in every sample become int64; a single fractional value turns the field into float64.
- RFC 3339 timestamps are typed as time.Time, which encoding/json parses without custom code; switch date detection off to keep them as strings.
- The omitempty option adds ,omitempty to every tag, so zero values are left out when you marshal the struct back to JSON.
Where your data goes
Nowhere. This tool runs entirely in your browser: the text you paste is processed by the page and is never transmitted to a server or written to a log.
This tool is free and needs no account. Its results exist only in your open page and are not saved anywhere.
What it costs
This tool is free, with no sign-in and no points.
Common questions
- Why are some fields pointers?
- A pointer is how Go tells "absent or null" apart from the zero value. homepage in the GitHub sample is a string for one repository and null for the other, so it becomes *string. A plain string would turn null into an empty string, and you could no longer tell the two cases apart.
- Why is a field typed interface{}?
- When every sample value is null there is no type to infer, so the field is left as interface{}, which accepts anything. Replace it with the real type once you know it, or include a sample in which the field is set and generate again.
- Is this the same as mholt/json-to-go?
- It does the same job — Matt Holt's json-to-go is the long-standing browser tool for it — but the engine here is quicktype, which merges identical shapes into one struct and marks optional fields by comparing array elements. The output style is close enough that structs from either fit the same codebase.
- Should I turn on omitempty?
- Only if an empty value really means "leave it out". With omitempty, false, 0 and the empty string disappear when you marshal, so an API that distinguishes false from missing will read your request differently. For structs you only ever unmarshal into, the tag changes nothing.
The open-source behind it
This tool runs on glideapps/quicktype, released under Apache-2.0. If you need the same behaviour inside your own program, that is the library to reach for.
glideapps/quicktypeAlso known as
- json to go
- json to go struct
- golang struct generator
- json to struct online
- go json tags
- convert json to golang