Skip to content
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

Change JQ to process newline-delimited JSON #227

Merged
merged 4 commits into from
Mar 22, 2025

Conversation

tho
Copy link
Contributor

@tho tho commented Mar 19, 2025

Update JQ filter to handle newline-delimited JSON (NDJSON).

Fixes #226.

Implementation Notes

  • Used decoder's More() method for cleaner iteration over JSON stream
  • Preserved existing code style with short variable names
  • Preserved error handling approach with early returns
  • Preserves interface{} usage instead of any
  • No return value checks for fmt.Fprintln
  • Direct return of external package errors without wrapping
  • Wrote individual tests instead of table driven tests

Example

Analyzes logs to count and display frequency of different log levels from newline-delimited JSON input.

cat log.json | ./goscript.sh -c 'script.Stdin().JQ(".level").Freq().Stdout()'
3 "INFO"
2 "WARN"
1 "ERROR"

tho and others added 2 commits March 19, 2025 07:11

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
https://jsonlines.org

Example use case:

Analyzes logs to count and display frequency of different log levels
from newline-delimited JSON input.

```
cat log.json | ./goscript.sh -c 'script.Stdin().JQ(".level").Freq().Stdout()'
3 "INFO"
2 "WARN"
1 "ERROR"
```

Verified

This commit was signed with the committer’s verified signature.
@bitfield
Copy link
Owner

@tho great work! I've made a few minor tweaks for house style and so on—are you okay with these?

Copy link
Contributor Author

@tho tho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Thanks for the quick review!

@bitfield bitfield merged commit 348e77b into bitfield:master Mar 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a filter to handle newline-delimited JSON
2 participants