LoginSignup
3
2

More than 5 years have passed since last update.

jqでjson形式の行だけ抽出する

Posted at

以下のようにjson形式の行とそうでない行が混在しているファイルにjqを実行してもparseエラーになってしまう。

php
java
{"lang": "go"}
ruby
{"lang": "perl"}

次のようなコマンドでjson形式の行だけ抽出することができた。

$ cat lang.json | jq -R 'fromjson? | select(type == "object")'

{
  "lang": "go"
}
{
  "lang": "perl"
}
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2