From 86b712bfce3b0f57be197d6839138aea03034f1f Mon Sep 17 00:00:00 2001 From: JP Appel Date: Sun, 13 Jul 2025 18:10:26 -0400 Subject: Correct multi-doc json output --- pkg/query/outputs.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'pkg/query/outputs.go') diff --git a/pkg/query/outputs.go b/pkg/query/outputs.go index a37cded..92331ef 100644 --- a/pkg/query/outputs.go +++ b/pkg/query/outputs.go @@ -139,21 +139,11 @@ func (o JsonOutput) Output(docs []*index.Document) (string, error) { } func (o JsonOutput) OutputTo(w io.Writer, docs []*index.Document) (int, error) { - n := 0 - for _, doc := range docs { - b, err := json.Marshal(doc) - if err != nil { - return n, err - } - - nn, err := w.Write(b) - if err != nil { - return n, err - } - n += nn + b, err := json.Marshal(docs) + if err != nil { + return 0, err } - - return n, nil + return w.Write(b) } func ParseOutputFormat(formatStr string) ([]OutputToken, []string, error) { -- cgit v1.2.3