Golang標準のjsonパッケージでは、jsonをstructに展開する方法として、 json.Unmarshal という関数と、 json.NewDecoder でデコーダを生成し、 Decode 関数を呼ぶ方法がある。 インターフェイスは、 func Unmarshal(data []byte, v any) error func NewDecoder(r io.Reader) *Decoder と func (dec *Decoder) Decode(v any) error バイト列を渡すのと、io.Readerから渡すという点が異なるが、これによる挙動の違いが最初わかっていなかった。 違いの結論 Unmarshalに渡すバイト列はひとつのjsonとして正しい形式である必要がある Decoderにio.Readerを渡してDecodeする方法は、Decodeはストリームから次のj