Suppress JQ parse error messages in linux
Asked Answered
H

1

8

I am looking to parse the json file using JQ utility in bash script , though i am able to parse it correctly , whenever there's invalid json content we get parse error message on the cmd line . So Question is how do we suppress that parse error message from the screen .

Why do i want to suppress the parse error messsage ? I am running through loop for evaluating certain conditions in json file , for which i need to parse it first using jq. So whenever the script runs and it encounters invalid json which it is not able to parse we get series of parse error message on the screen , which is something i want to suppress .

Hong answered 8/12, 2016 at 9:2 Comment(2)
Send it to /dev/null ?Galop
jq <<< 'invalid json' 2>/dev/nullBarimah
W
4

If you want jq to ignore errors, then consider handling the error programmatically within jq, e.g.

$ jq -n 'try inputs catch "The end"' <<< 'silly'
"The end"

(Note the use of the -n option.)

Wendish answered 8/12, 2016 at 9:43 Comment(2)
Could you explain (and perhaps link) the -n option please?Tasse
The -n option stops jq from reading the input stream unless the program directs it to do so (via input and/or inputs). See stedolan.github.io/jq/manual/#InvokingjqWendish

© 2022 - 2024 — McMap. All rights reserved.