-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add -json option #509
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
Add -json option #509
Conversation
Prints newline-delimited JSON output to STDOUT
joohoi
left a comment
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.
Thanks for the PR! I think jsonline format is really useful to have for different integration purposes.
I added a few change requests and / or proposals, but in general the PR look good
For each JSON result being printed, prepend it with a TERMINAL_CLEAR_LINE via STDERR. This clears the progress line (which is also being emitted via STDERR) and leaves us with a clean stream of JSON lines in the terminal.
joohoi
left a comment
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.
Thanks for the fixes, it seems all good. One more small thing, I'd like the flag to be called -jsonlines instead of -json in order to not to confuse people too much. I think JSONlines is the somewhat official name for that data format, re: https://jsonlines.org/
|
Hi @justinsteven , are you interested in making the last very small change? I can also do this for you if you wish though. (also there seems to be a merge conflict caused by other PR's getting merged while this has been open) |
|
Yes, sorry, I've been tied up and I missed that you'd said that abstracting the I'm happy to change I could clarify via the help that If you think it's clearer and easier for users if it's |
joohoi
left a comment
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.
Ok, I think you have a fair point here. My thinking was that -json could confuse people with the json output file format and jsonlines output. Let's do it your way.
* Add -json option Prints newline-delimited JSON output to STDOUT * sort * Clear terminal line via STDERR foreach JSON result For each JSON result being printed, prepend it with a TERMINAL_CLEAR_LINE via STDERR. This clears the progress line (which is also being emitted via STDERR) and leaves us with a clean stream of JSON lines in the terminal.
Prints newline-delimited JSON output to STDOUT
Resolves #205
Description
Adds the
-jsonoption and makes it mutually exclusive with-v. Operates similarly to-vin that it changes the behavior of the stdout outputter, causing result lines to be stringifiedjson.Marshal(result)output.By simply changing stdout to be JSON-formatted, new use cases include:
teeto do this while monitoring results via the terminalAside from making
-jsonbe mutually exclusive with-v, no other thought was given to compatibility with other features.Demo
The progress output causes typical output to be messy:
Use of
teeandjqwhile throwing away stderr to clean up the output:Additonally
CONTRIBUTORS.md.The file should be alphabetically ordered.
CHANGELOG.md