Unfortunately there is not a more elegant way. Unless you change the protocol, and dispense with the idea of returning a single json object, and instead return line delimited streaming json. Then you can dispense with injecting brackets into your stream, and just call
enc.Encode(doc) w.Write([]byte('\n')) for each doc On Wednesday, 19 February 2020 13:15:36 UTC, Jérôme LAFORGE wrote: > > Hello, > Do you know an elegant, simple and clean way to stream an json array > inside json object? > > Here an example, that does the job, but I find it complicated (and how we > manage the comma when document has error and we have to ignore it) > > https://play.golang.org/p/lZa8iVaQAKg > > thx in adv > BR > 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/1ab33d01-9885-4874-b260-0efab4f13738%40googlegroups.com.