> json | go | struct <
// Generate Go struct definitions from JSON with json tags, omitempty, and pointer toggles
Encoding/json Tag Output
Every Go field carries a struct tag matching the original JSON key, so encoding/json round-trips back to the exact field names you supplied.
Nested Structs or Inline
Choose flattened top-level struct definitions for reuse, or keep nested objects inlined for compact, single-block output.
Pointer / Omitempty Options
Toggle pointer types and json:"foo,omitempty" tags for optional fields detected via null or missing keys, matching idiomatic Go marshaling.
// ABOUT JSON TO GO
How It Works:
The generator parses JSON with JSON.parse, walks the document tree, and emits one Go type per nested object. Field names become PascalCase, common initialisms (ID, URL, API, HTTP, JSON) are upper-cased to match the encoding/json package conventions, and primitive values map to int, float64, string, or bool. Arrays become Go slices; null or missing keys mark a field optional.
Example:
{"id": 1, "name": "Alice"} -> type Root struct { ID int `json:"id"`; Name string `json:"name"` }
Common Use Cases:
- >Bootstrap Go models from third-party REST API responses
- >Generate types for json.Unmarshal and json.Decoder targets
- >Stub request and response structs for new HTTP endpoints
- >Migrate Python or Node services to Go without retyping every field
- >Document JSON contracts as compilable, reviewable Go code
>> frequently asked questions
Q: How are JSON keys converted to Go field names?
A: Each JSON key is split on non-alphanumeric characters, every fragment is title-cased, and common initialisms (ID, URL, HTTP, API, JSON, XML, SQL, UUID, HTML, CSS, IP, TCP, UDP, SSL, TLS, CPU, RAM) are fully upper-cased. This matches the conventions enforced by golangci-lint's revive and stylecheck rules, so your generated structs pass review without manual renaming.
Q: When should I enable pointers and omitempty?
A: Use pointers and omitempty when you must distinguish a missing field from a zero value (empty string, false, 0). With encoding/json, value-typed zero fields cannot be told apart from absent fields once both omitempty is set; pointer-typed nil fields are unambiguously omitted, which matters for PATCH-style APIs and partial-update payloads.
Q: How is int vs float64 decided?
A: If every observed value for a given field is a JavaScript integer with no decimal part, the type is int. As soon as one value carries a fractional part, the field is widened to float64. If you need int64 precision for large integers, edit the generated type after copying — the JSON spec does not actually constrain numeric width.
Q: What happens with an array of objects at the root?
A: The tool emits one struct describing the merged element shape and defines the root as a slice (e.g. type Root []RootItem). Keys present in some elements but missing in others are automatically marked optional, so unmarshaling heterogeneous arrays still validates without panics.
Q: Is my JSON sent to a server?
A: No. Conversion runs entirely in your browser using JSON.parse and a small recursive Go-emitter. There is no upload, no telemetry, and no server round-trip; the page is fully client-side and works offline once cached, so even confidential payloads can be parsed safely.