diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index 361e3023..b4d9b9f0 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -34,7 +34,7 @@ func NewPrinter(writer io.Writer, outputToJSON bool, unwrapScalar bool, colorsEn unwrapScalar: unwrapScalar, colorsEnabled: colorsEnabled, indent: indent, - printDocSeparators: printDocSeparators, + printDocSeparators: !outputToJSON && printDocSeparators, firstTimePrinting: true, treeNavigator: NewDataTreeNavigator(), } diff --git a/pkg/yqlib/printer_test.go b/pkg/yqlib/printer_test.go index fdb51736..5bad9ff5 100644 --- a/pkg/yqlib/printer_test.go +++ b/pkg/yqlib/printer_test.go @@ -130,7 +130,9 @@ func TestPrinterMultipleDocsInSinglePrint(t *testing.T) { func TestPrinterMultipleDocsJson(t *testing.T) { var output bytes.Buffer var writer = bufio.NewWriter(&output) - printer := NewPrinter(writer, true, true, false, 0, false) + // note printDocSeparators is true, it should still not print document separators + // when outputing JSON. + printer := NewPrinter(writer, true, true, false, 0, true) inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml", 0) if err != nil {