Generate Go Types from Complete JSON Examples
Infer Go structs and raw maps locally, preserve lexical numbers with json.Number and explain optional pointer capabilities.
Tool workspace
JSON to Go
Go 1.22+ declarations; encoding/json and standard library only.
All numbers use json.Number to preserve their lexemes. Optional pointers accept null even without a null sample, and collapse absence/null to nil; omitempty may omit explicit null. Raw fields preserve null tokens. Structs do not enforce required fields or reject scalar null. Unsafe tag keys widen the whole object to a raw map.
Enable JavaScript to generate code. You can still read and edit JSON.
This browser cannot start the local Worker. Generation is unavailable.
All elements and documents contribute to one contract. An array root stays an array. An absent field differs from null.
Up to 20 documents, 1,000,000 UTF-16 input units and 2,000,000 output units; other resource budgets also apply.
Your JSON is processed locally in a browser Worker. It is not uploaded or stored.
Changing to one document keeps only the active example. Confirm or cancel.
Use 1–64 ASCII letters and digits, beginning with a letter. Reserved names are rejected.
Ready for JSON input.
Some diagnostic details are omitted. Notice totals remain visible.
Name details
Clipboard is unavailable or denied. Download the file or explicitly open the complete code for manual copying. A large file may take longer to display.
Complete examples and root arrays
Paste strict JSON or choose a local UTF-8 file. Generate from one document or up to twenty complete examples. Every element and late field contributes; a root array stays an array. Empty inputs, decoded duplicate keys, comments, trailing commas and concatenated documents stop generation without losing your examples.
The editor shows the active example and total count. After generating, review the filename, root type expression, JSON node count and size of the complete code. These details describe the current result; copying and downloading include the full file even when the preview is shortened.
[{"id":1},{"id":2,"nombre":"Ana"}]
package generated
import "encoding/json"
type RootItem struct {
Id json.Number `json:"id"`
Nombre *string `json:"nombre,omitempty"`
}
type Root []RootItem
Exact tags, maps and pointer presence
Nonempty keys matching [A-Za-z0-9_ .:/-]+ receive exported struct fields with exact json tags. A literal - uses json:"-," or json:"-,omitempty". Identifier collisions change only Go field names. Any other key, including quotes, commas, backslash, backtick, controls or Unicode, widens the whole object to a named map[string]json.RawMessage; every valid Unicode key remains available in the map. Isolated surrogates in keys stop generation. Empty objects also become raw maps.
An absent field uses *T and omitempty, except raw fields. Observed T plus null uses one pointer, never two. Present false, zero and empty strings remain nonnil pointers. Optional pointers accept null even if none was observed; absence and null both become nil, so a later serialization may omit explicit null. Raw fields distinguish nil absence from the received null token. Go does not enforce required keys or reject scalar null during deserialization. Notices explain these capabilities; generated types are not runtime validation or a global round-trip guarantee.
Numbers and complete local exports
Every number is json.Number, including 9007199254740993, 1.0, 1e3 and -0. Its String() preserves the original lexeme without a float64 conversion. Parser precision notices remain visible but do not imply loss by json.Number. Unknown, null-only and unions of two or more nonnull branches use json.RawMessage with notices. A number or raw root uses an alias that retains unmarshalling methods; object/null uses a pointer alias. Only reachable declarations and required imports are emitted in package generated, with no custom deserializer.
Limits: 20 samples, 1,000,000 UTF-16 input units, 4,000,000 UTF-8 bytes in total and per file, depth 200, 100,000 source nodes/inference visits, 1,000,000 parse work units, 10,000 types, 20,000 fields, 2,000,000 merge work units, 2,000 declarations, 4,000,000 emission work units and 15 seconds. Output allows 2,000,000 UTF-16 units and 8,000,000 bytes. These maxima cannot necessarily be reached together; exceeding a hard limit yields no partial code.
The preview contains at most 20,000 UTF-16 units; copy and download include the entire current types.go as text/plain;charset=utf-8, UTF-8 without BOM and LF with a final newline. At most 100 diagnostic details and 50 name rows totaling 10,000 units are shown with omitted counts. Denied clipboard access offers explicit manual copying of complete code. One initial BOM is removed only for parsing; positions use the original editor text. Cancel terminates the Worker; edits, mode, sample order and options invalidate the output. Processing stays in a local Worker, offline after assets load, without uploads, storage or data in related links. JavaScript and Worker support are required; generated Go is never compiled or executed in the browser.