LoginSignup
10
8

More than 5 years have passed since last update.

jqで連続するオブジェクトを配列にする

Posted at

以下のようなやつ。

$ echo '{ "a": "1" }' '{ "b": "2"}' | jq
{
  "a": "1"
}
{
  "b": "2"
}

-s を使うと配列にできる

echo '{ "a": "1" }' '{ "b": "2"}' | jq -s
[
  {
    "a": "1"
  },
  {
    "b": "2"
  }
]

manにはこうかいてある

--slurp/-s:

           Instead  of  running  the  filter  for each JSON object in the
           input, read the entire input stream into a large array and run
           the filter just once.
10
8
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
10
8