JQコマンドでJSONの特定の値を抽出したい
JQコマンドでのJSONの加工をして、特定の値のみ抽出したいのですが、
マニュアルやサイトを見て、いろいろ試行錯誤したのですが、
どうしたらよいかわかりません。
どなたか、助けていただけないでしょうか?
詳細は、下記のようになります。
元データ
[
{
"room_id": 99999999,
"name": "佐藤一郎",
"type": "direct",
"role": "member",
"sticky": true,
"unread_num": 2,
"mention_num": 1,
"mytask_num": 0,
"message_num": 28,
"file_num": 3,
"task_num": 0,
"icon_path": "https://appdata.chatwork.com/avatar/99999999/99999999.png",
"last_update_time": 1556586317
},
{
"room_id": 88888888,
"name": "山田 花子",
"type": "direct",
"role": "member",
"sticky": false,
"unread_num": 0,
"mention_num": 0,
"mytask_num": 0,
"message_num": 1,
"file_num": 0,
"task_num": 0,
"icon_path": "https://appdata.chatwork.com/avatar/88888888/88888888.rsz.jpg",
"last_update_time": 88888888
}
]
得たい結果
999999999
88888888
試したコマンドと実行結果
$ curl -X GET -H "X-ChatWorkToken: XXXXXXXX" "https://api.chatwork.com/v2/rooms/" | jq 'room_id'
jq: error: room_id/0 is not defined at <top-level>, line 1:
room_id
jq: 1 compile error
curl: (23) Failed writing body (0 != 16384)
$ curl -X GET -H "X-ChatWorkToken: XXXXXXXX" "https://api.chatwork.com/v2/rooms/" | jq '.room_id'
jq: error (at <stdin>:0): Cannot index array with string "room_id"
$ curl -X GET -H "X-ChatWorkToken: XXXXXXXX" "https://api.chatwork.com/v2/rooms/" | jq '[room_id]'
jq: error: room_id/0 is not defined at <top-level>, line 1:
[room_id]
jq: 1 compile error
curl: (23) Failed writing body (0 != 16384)
$ curl -X GET -H "X-ChatWorkToken: XXXXXXXX" "https://api.chatwork.com/v2/rooms/" | jq '[.room_id]'
jq: error (at <stdin>:0): Cannot index array with string "room_id"
$ curl -X GET -H "X-ChatWorkToken: XXXXXXXX" "https://api.chatwork.com/v2/rooms/" | jq '[{room_id}]'
jq: error (at <stdin>:0): Cannot index array with string "room_id"
$ curl -X GET -H "X-ChatWorkToken: XXXXXXXX" "https://api.chatwork.com/v2/rooms/" | jq '[{.room_id}]'
jq: error: syntax error, unexpected FIELD (Unix shell quoting issues?) at <top-level>, line 1:
[{.room_id}]
jq: 1 compile error
curl: (23) Failed writing body (0 != 16384)