Skip to content

Commit 557b4fb

Browse files
authored
removed trailing comma from the jsonl exporter (#5861)
* removed trailing comma from the jsonl exporter * adding the O_TRUNC flag when opening the file to explicitly indicate that the file should be truncated if it exists.
1 parent 1f98545 commit 557b4fb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

pkg/reporting/exporters/jsonl/jsonl.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (exporter *Exporter) WriteRows() error {
7070
var err error
7171
if exporter.outputFile == nil {
7272
// Open the JSONL file for writing and create it if it doesn't exist
73-
exporter.outputFile, err = os.OpenFile(exporter.options.File, os.O_WRONLY|os.O_CREATE, 0644)
73+
exporter.outputFile, err = os.OpenFile(exporter.options.File, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
7474
if err != nil {
7575
return errors.Wrap(err, "failed to create JSONL file")
7676
}
@@ -86,8 +86,7 @@ func (exporter *Exporter) WriteRows() error {
8686
return errors.Wrap(err, "failed to generate row for JSONL report")
8787
}
8888

89-
// Add a trailing newline to the JSON byte array to confirm with the JSONL format
90-
obj = append(obj, ',', '\n')
89+
obj = append(obj, '\n')
9190

9291
// Attempt to append the JSON line to file specified in options.JSONLExport
9392
if _, err = exporter.outputFile.Write(obj); err != nil {

0 commit comments

Comments
 (0)