Go JSON

Guides encoding/json correctly — only exported fields marshal (a lowercase field is silently dropped), struct tags (`json:"name,omitempty"`, `json:"-"`, `,string`), the omitempty-vs-omitzero (Go 1.24) trap where omitempty does NOT drop a zero struct or time.Time, decoding into interface{} yielding map[string]any with every number a float64 (precision loss → json.Number / UseNumber), Decoder/Encoder for streams, DisallowUnknownFields, custom MarshalJSON, json.RawMessage, and always checking the Marshal/Unmarshal error. Auto-invokes when writing or editing struct json tags, json.Marshal/Unmarshal, encoding/json, Decoder/Encoder, omitempty/omitzero, or on "why is this field missing in the JSON" / "why is my number a float64" requests. The struct tag is a contract; the surprises are all in the defaults.

ctoth 51d11ed 3 files · 27.5 KB Updated

File contents

ctoth/golang-skills-plugin/tree/main/plugins/golang/skills/go-json commit 51d11ed213

Frequently asked questions

npx skillmds@latest add ctoth/go-json