Hello,
I would like to know if there is elegant way to json encode very long field 
(with io.Reader)?

For example: (play ground https://go.dev/play/p/QxlbNMy3ERK )
```
func TestJSONStreamBytes(t *testing.T) {
    type MyStruct struct {
        Reader1 io.Reader `json:"field1"`
        Reader2 io.Reader `json:"field2"`
    }

    out := &bytes.Buffer{}

    err := json.NewEncoder(out).Encode(MyStruct{
        Reader1: strings.NewReader("this stream can be very long from S3 
Bucket for example"),
        Reader2: strings.NewReader("this stream can be very long from 
another S3 Bucket for example"),
    })
    if err != nil {
        panic(err)
    }

    t.Log(out.String())
}
```
It returns prog.go:29: {"field1":{},"field2":{}}

But I want base64encoded response managed as stream mode (i.e. I don't want 
to load the data in our memory) like :

{"field1":"dGhpcyBzdHJlYW0gY2FuIGJlIHZlcnkgbG9uZyBmcm9tIFMzIEJ1Y2tldCBmb3IgZXhhbXBsZQ==","field2":"dGhpcyBzdHJlYW0gY2FuIGJlIHZlcnkgbG9uZyBmcm9tIGFub3RoZXIgUzMgQnVja2V0IGZvciBleGFtcGxl"}


Thank in advance,
Jérôme

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3359268b-027f-48bf-baa8-ab8cadd89363n%40googlegroups.com.

Reply via email to