-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
removed trailing comma from the jsonl exporter #5861
Conversation
WalkthroughThe changes in this pull request involve a modification to the Changes
Possibly related issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
pkg/reporting/exporters/jsonl/jsonl.go (1)
Line range hint
71-75
: Consider adding O_TRUNC flag for file creationWhile the current implementation works correctly, consider adding the
O_TRUNC
flag when opening the file to explicitly indicate that the file should be truncated if it exists. This makes the behavior more explicit.- 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)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
pkg/reporting/exporters/jsonl/jsonl.go
(1 hunks)
🔇 Additional comments (1)
pkg/reporting/exporters/jsonl/jsonl.go (1)
89-89
: LGTM! Change correctly implements JSONL format
The modification to append only a newline character (\n
) instead of comma+newline properly aligns with the JSON Lines specification, which requires each JSON object to be on its own line without trailing commas.
Let's verify the output format:
✅ Verification successful
Let's gather more information by checking the test files to verify the JSONL export functionality:
Let's verify the implementation by checking the WriteRows method:
Based on the code inspection, I can now provide a final response about the JSONL format change:
LGTM! The JSONL format implementation is correct
The implementation in WriteRows()
properly handles JSONL format by:
- Converting each record to JSON using
json.Marshal()
- Appending only a newline character (
\n
) after each JSON object - Writing each line sequentially to the file
This aligns with the JSONL (JSON Lines) specification which requires:
- One complete JSON object per line
- No trailing commas between objects
- Lines separated by newline characters
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify JSONL output format compliance
# Expected: Each line should be a valid JSON object without trailing commas
# Search for any test files that might contain sample JSONL output
fd -e jsonl -x sh -c 'echo "=== {} ==="; cat {} | jq -c "." || echo "Invalid JSONL format"'
# Also check if there are any tests validating the output format
rg -A 5 "TestJSONLExporter|jsonl.*export"
Length of output: 3479
Script:
#!/bin/bash
# Search for test files related to JSONL exporter
fd -e go -x grep -l "jsonl" {} | xargs cat
# Specifically look for test cases in the same directory
ast-grep --pattern 'func Test$_($_) {
$$$
}' pkg/reporting/exporters/jsonl/jsonl.go
# Check if there are any example or test data files
fd -e json -e jsonl -e txt -x sh -c 'echo "=== {} ==="; head -n 5 {}'
Length of output: 100960
Script:
#!/bin/bash
# Look for WriteRows implementation
ast-grep --pattern 'func (exporter *Exporter) WriteRows() error {
$$$
}' pkg/reporting/exporters/jsonl/jsonl.go
# Also check if there are any tests that verify the output format
ast-grep --pattern 'func Test$_($_) {
$$$
jsonl$_
$$$
}' pkg/reporting/exporters/jsonl/jsonl_test.go
Length of output: 3065
…that the file should be truncated if it exists.
Thanks for your contribution @bf-rbrown ! |
Proposed changes
This PR removes the trailing comma from the jsonl exporter (
-jsonl-export
flag) to comply with jsonlines formatting.This addresses #5860
The current implementation creates a file that is comma and newline terminated. While this works as an output file, the file does not work when ingested into other programs:
This PR removes the comma from each row in the output:
Checklist
Summary by CodeRabbit
New Features
Bug Fixes