Skip to content

Commit

Permalink
removed trailing comma from the jsonl exporter (#5861)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bf-rbrown authored Dec 1, 2024
1 parent 1f98545 commit 557b4fb
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/reporting/exporters/jsonl/jsonl.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (exporter *Exporter) WriteRows() error {
var err error
if exporter.outputFile == nil {
// Open the JSONL file for writing and create it if it doesn't exist
exporter.outputFile, err = os.OpenFile(exporter.options.File, os.O_WRONLY|os.O_CREATE, 0644)
exporter.outputFile, err = os.OpenFile(exporter.options.File, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return errors.Wrap(err, "failed to create JSONL file")
}
Expand All @@ -86,8 +86,7 @@ func (exporter *Exporter) WriteRows() error {
return errors.Wrap(err, "failed to generate row for JSONL report")
}

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

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

0 comments on commit 557b4fb

Please sign in to comment.