Dont print doc separators for JSON (https://github.com/mikefarah/yq/issues/735)

This commit is contained in:
Mike Farah 2021-03-19 12:40:34 +11:00
parent f7b50e9853
commit 3722367fbb
2 changed files with 4 additions and 2 deletions

View File

@ -34,7 +34,7 @@ func NewPrinter(writer io.Writer, outputToJSON bool, unwrapScalar bool, colorsEn
unwrapScalar: unwrapScalar, unwrapScalar: unwrapScalar,
colorsEnabled: colorsEnabled, colorsEnabled: colorsEnabled,
indent: indent, indent: indent,
printDocSeparators: printDocSeparators, printDocSeparators: !outputToJSON && printDocSeparators,
firstTimePrinting: true, firstTimePrinting: true,
treeNavigator: NewDataTreeNavigator(), treeNavigator: NewDataTreeNavigator(),
} }

View File

@ -130,7 +130,9 @@ func TestPrinterMultipleDocsInSinglePrint(t *testing.T) {
func TestPrinterMultipleDocsJson(t *testing.T) { func TestPrinterMultipleDocsJson(t *testing.T) {
var output bytes.Buffer var output bytes.Buffer
var writer = bufio.NewWriter(&output) 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) inputs, err := readDocuments(strings.NewReader(multiDocSample), "sample.yml", 0)
if err != nil { if err != nil {