Is jq guaranteed to always output valid json, even if it encounters an error while running? Error could be due to poorly formatted input, for example. Outputting valid json and not outputting anything are both okay, but partially outputting a json (which ends up invalid json) and then exiting would be a problem for my use case.
So far I've not faced this issue, but I would still prefer a guarantee that it can't happen. I'm about to use jq as part of a bash pipeline for a machine learning task that costs a non-trivial amount to run.
I couldn't find this in the docs. I could probably read the source code but that'll take a lot of time.
-
Nothing is ever guaranteed to have valid output when it errors out. E.g. bugs exist. Even if errors were handled to still present something in case they happen, the code for that could also get broken in some way. This question doesn't make much sense IMO.Destroy666– Destroy6662025年01月09日 11:13:07 +00:00Commented Jan 9 at 11:13
1 Answer 1
The jq command will output an error on stderr when it encounters invalid JSON. If the JSON is valid, it will output the JSON on stdout. If it crashes while outputting the JSON, the output could theoretically be invalid JSON.
You cannot guarantee that jq will not crash.
You must log in to answer this question.
Explore related questions
See similar questions with these tags.