encoding/json, yaml adapters, csv parsing, base64, and strict schema decoding.
6 min readGo for SREBuild
JSON Encoding
encoding/json is the standard JSON package. It handles marshaling, unmarshaling, streaming, and struct tags. It is fast enough for most use cases.
Gojson-operations.go
40 linesLn 1, Col 1Go
json.MarshalIndent produces human-readable output. json.Decoder streams from io.Reader — more efficient for large payloads. json.RawMessage delays parsing — useful for polymorphic types. omitempty omits zero values.
YAML Handling
Goyaml-operations.go
37 linesLn 1, Col 1Go
yaml.v3 is the standard YAML package. It supports streaming, multi-document files, and struct tags. SetIndent controls indentation. yaml.v3 handles YAML 1.2 and is more strict than yaml.v2.
StdEncoding uses A-Z, a-z, 0-9, +, /. URLEncoding replaces + and / with - and _ for URLs. RawStdEncoding omits padding. Stream encoding/decoding is efficient for large data.
Strict Decoding
Gostrict-json-decoding.go
43 linesLn 1, Col 1Go
DisallowUnknownFields rejects JSON with unexpected fields — catches typos and config drift. Validate after decoding to enforce business rules. Combine strict decoding with validation for robust configuration loading.
Streaming Encoding
Gostreaming-json-processing.go
38 linesLn 1, Col 1Go
Streaming decode processes one item at a time without loading the entire array into memory. json.Decoder.Token reads structural tokens (brackets, commas). json.More checks if there are more items. This handles gigabyte-sized JSON files.
Use streaming for large payloads
json.Unmarshal loads the entire payload into memory. json.NewDecoder streams from an io.Reader. For large files or network responses, always use streaming decode to prevent memory exhaustion.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.