jq
jq copied to clipboard
stderr doesn't print raw
Describe the bug stderr doesn't print its input as a raw string but as an escaped json string.
To Reproduce
jq -n '"line1\nline2" | stderr | empty'
Outputs "line1\nline2"
Expected behavior As the manual states:
stderr Prints its input in raw and compact mode to stderr with no additional decoration, not even a newline.
I expected the program to output be:
line1
line2
Environment (please complete the following information):
- OS and Version: Redhat Enterprise Linux 6
- jq version 1.6
This is not a bug, but a feature. Perhaps stderr
should output raw when jq is in raw output mode, or perhaps we need a new rawstderr
builtin. Or perhaps we can leave this to the I/O work we're doing, and then the user can open /dev/null
in raw mode.
The documentation is somewhat misleading
stderr Prints its input in raw and compact mode to stderr with no additional decoration, not even a newline.
Would let you believe that stderr behave like --raw-output
and --compact-output
. "Not even a new line" is where it differs from --compact-output
.
Perhaps another word than "raw" could be used here?
Yeah this is a bug IMO -- either the behavior or the documentation should be fixed, because right now they're inconsistent.
I am really enjoying jq - unfortunately I tripped up on this as well
I perused the docs quite extensively and it seems there is no way to print an arbitrary string (with escape sequences) to standard error?
I can't use stderr
because newlines of its input are automatically escaped. halt_error
prints the way I want, but it halts the program. The only way I have been able to print a newline to stderr is through debug
- its an unfortunate unaesthetic workaround, but it works.
I don't think that the behavior of stderr
should change based on if jq is in raw mode. If it is not possible in one way or another to change stderr, I would welcome another function that yields the expected behavior.
Just wanted to register a +1
on folks who have run into this surprising behavior.
+1
from me, too. I was really hoping to provide a customized warning, but since I cannot get stderr
to actually create a newline, I guess I'm stuck with debug
.
FWIW, I ended up here because I was trying to do something like this:
. as $line | try fromjson catch $line | stderr
I'm filtering ndjson logs and wanted to be able to use the try fromjson
to filter valid json log lines that I could then pipe into further transforms, and wanted to be able to just redirect malformed lines to stderr