JSON to Go Converter
Generate Go structs with json tags from a sample — exported fields, correct types, nested structs, ready for encoding/json.
Structs and tags without the typing
Go's encoding/json needs two things to unmarshal an API response: exported field names and json:"…" tags matching the wire keys. Writing both by hand for a deep response is pure toil — and one typo in a tag silently zeroes the field. The generator does the mapping for you: user_id becomes UserID int64 `json:"user_id"`, nested objects become named struct types, arrays become slices.
Idiomatic choices baked in
- Initialisms —
id,url,apicome out asID,URL,API, the way golint expects. - int64 / float64 — JSON numbers carry no width, so the safe defaults are used; tighten types where your domain allows.
- Pointers for nullables — fields that appear as
nullin the sample become pointer types (*string), the Go convention for "may be absent".
From sample quality to struct quality
The structs mirror your sample: arrays with a single element teach the generator less than arrays with several, and consistently-typed fields produce cleaner results than wildly mixed ones. Garbage in, interface{} out — if you see an unexpected interface type, your sample mixed types in that field. Validate and inspect the sample first with the tree viewer when in doubt.
Frequently asked questions
Why are some fields pointers (*string) instead of plain types?
Fields that appear as null in the sample become pointers — the idiomatic Go signal for "value may be absent", distinguishing empty from missing. If you prefer zero values, drop the pointer and the distinction.
Are the json tags really necessary?
Whenever the wire key differs from the exported Go name — which is almost always, since JSON keys are rarely UpperCamelCase — yes. A missing or misspelled tag does not error; the field just stays zero. Generated tags remove that whole bug class.
What happens with mixed-type fields?
A field that is sometimes a string and sometimes a number in the sample cannot get a concrete type — it falls back to interface{}. Fix the data (or the API) rather than fighting the type.
Does the output need any third-party packages?
No — plain structs for the standard library encoding/json. json.Unmarshal(data, &v) and you are running.