Can i somehow output the input data in case of an error, or at least a more detailed error output with the part of the string which is not correct?
Thanks
@m42e - Which version of jq are you using? I ask because jq version 1.5 gives detailed information about the location of data errors, e.g.:
parse error: Expected another array element at line 3, column 4
Version 1.5 of jq also provides filters that are very useful for debugging, notably debug/0.
Yes, but in my case, I'm getting some text using curl and directly pipe it into jq. I'm using jq for some tests of a REST api. And in the case I get an error I'd like to have the text where the error occurs rather than the position.
I switched to write it to a file, and cat it out, if jqs exit code is not 0, using the --exit-status flag.
I'm using 1.5.
@m42e - Using tee or equivalent is a good way to go. Given the orientation of jq to valid JSON texts, the reluctance of the jq maintainers to add new command-line flags, and the difficulty of devising a generally useful approach to the problem that does not contain arbitrary elements, I doubt that much will change on the jq side.
That's ok for me. I didn't want to change jq. Just want to know if there is a way to do it inside jq. The workaround is ok for me.
If the error is a jq program error then you can try/catch and you can output the input with debug.
I wanted something similar for tailing my logs (and a few of the lines aren't json on startup)
Here's what I came up with depending if I care or not about the non json lines.
# Include All Errors in output as a string
cat example.log | jq -R '. as $raw | try fromjson catch $raw'
# Skip all errors and keep going
cat example.log | jq -R 'fromjson?'
Most helpful comment
I wanted something similar for tailing my logs (and a few of the lines aren't json on startup)
Here's what I came up with depending if I care or not about the non json lines.