ログファイルをtail -f
やdocker logs -f
で見たりする事ありますよね。もし、そのログファイルがjsonフォーマットだったら各ログ毎にjqしたものを見たいですよね。
logs.sh
docker logs --tail 10 -f greatapp | while read line
do
echo "$line" | jq -R -r '. as $line | try fromjson catch $line'
done
これがその答えです。
see also
How to skip non-json lines?
https://github.com/stedolan/jq/issues/884
𝑸: Is there a way to have jq keep going after it hits an error in the input file? Can jq handle broken JSON?
https://github.com/stedolan/jq/wiki/FAQ#general-questions