-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/vuln: govulncheck
output should be newline delimited json
#70824
Comments
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
see #60207 any json parsing tool should already be able to handle arbitrary whitespace between json elements. |
@seankhliao this is not related to #60207. This issue is about making the JSON event stream compliant to popular JSON event streaming specifications (NDJSON, JSONL)
Could you elaborate on why the decision was made to prettify a format that is made for machines? If users want pretty output, they should not use a format that is made for machines. |
Doing something with JSON streams usually looks something like this: (pseudocode)
It is hard to find the beginning / end of a JSON object via scripts, if it is prettified. |
Also, the current behavior is not consistent with some other JSON outputs in the go ecosystem like In #60207, you compared this to When users really want prettified JSON objects, they could stream the newline delimited JSON to something like jq. |
https://en.wikipedia.org/wiki/JSON_streaming#Concatenated_JSON we could say the same, where users needs ndjson (or some other json representation), they could use a tool like jq. |
Valid point.
True, but I think a format meant for machine readability should focus on machine readability first, and if someone wants to use the format in another way (which it wasn't made for) they can do the extra step. I guess both formats have their pros and cons. Thank you for clarifying :) |
Proposal
The
govulncheck
tool currently outputs JSON in a multi-line, prettified format. This makes parsing the output unnecessarily difficult, especially since the-format json
flag is intended for machine consumption, and machines do not care about pretty output.To improve usability and align with standard practices, the
govulncheck
tool should output newline-delimited JSON (NDJSON) when the-format json
flag is specified. This format ensures that each top-level JSON object is written as a single line, simplifying parsing and making it compatible with tools that process NDJSON. This is usually the preferred way of handling JSON streams.Using NDJSON is not a breaking change, as the JSON structure will remain the same, just outputted in a single line without indentation.
Benefits
Alternatives
As an alternative, a
-format ndjson
flag could be introduced. While this would ensure that-format json
isn't touched, it would output the exact same structures.Side note
NDJSON is not an alternative to JSON. It's bascially "one JSON object per line".
Reference: https://github.com/ndjson/ndjson-spec
The text was updated successfully, but these errors were encountered: