Last Updated: May 22, 2026
json.Marshal and json.Unmarshal work on a single []byte that holds the entire payload. That's fine for small request bodies and config files, but it falls apart the moment the data is big, slow to arrive, or doesn't fit in memory at all. The json package solves this with json.Encoder and json.Decoder, two types that wrap any io.Writer or io.Reader and process JSON one value at a time. This chapter covers when and how to use them, the small set of configuration knobs they expose, and the patterns that come up in HTTP handlers and log processors.