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.
This commit is contained in:
Richard Brown 2024-12-01 07:15:22 -06:00 committed by GitHub
parent 1f985459b8
commit 557b4fba38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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")
}
@ -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 {