Skip to content

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
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"
```
@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