スポンサーリンク
APIの試験やおためしで使う場合にcurlコマンドを使うのですが、
そこで得られた結果を加工する際にjqコマンドも一緒に良く使います。
今回はそんなjqコマンドを使っててプチハマりした内容をメモしておきます。
・aws EC2
・amazon linux
・jq-1.5
jqコマンドではキーワードを指定して検索するselectという機能があります(SQLのselectと同じような使い方ができます。)
それを使った時に以下のようなエラーが出てしまいました。
[ec2-user@ip-172-31-30-171 ~]$ curl http://localhost:8080/blogs | jq ".[] | select( .title == 'test1')"
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
.[] | select( .title == 'test1')
jq: 1 compile error
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3790 0 3790 0 0 257k 0 --:--:-- --:--:-- --:--:-- 264k
(23) Failed writing body
この時、返って来たjsonは以下なのでコマンド自体が間違っているわけでは無さそうです。
{
"id": 1,
"title": "test1",
"content": "this is test dayo",
"created_at": "2017-06-01T01:15:26.223Z",
"updated_at": "2017-06-01T01:15:26.223Z"
}
早速ですが原因はクォーテーションでした。
上記コマンドではjqコマンドの中身を"
でくくり、検索するキーワードを'
でくくっていますが、
正しくは逆にする必要がありました。
つまり正しいコマンドは以下の通りです。
curl -sS http://localhost:8080/blogs | jq '.[] | select(.title == "test1")'
{
"id": 1,
"title": "test1",
"content": "this is test dayo",
"created_at": "2017-06-01T01:15:26.223Z",
"updated_at": "2017-06-01T01:15:26.223Z"
}
これでうまく行きました。
ただ本来はエラーが起きてるコマンドでも正しく動くはずなのにな~?と思ったりしますが。
スポンサーリンク
2020/09/25 17:46:47
Prix Cialis Tadalafil usacybes https://cialiser.com/ - Cialis glicky Citalopram E Paroxetina Pouluffini cialis online purchase BenseneMuh Viagra 100 Mg Tabletas
2020/11/12 22:01:42
erectile aides for men
is erectile dysfunction common in older men
erectile pumps
erectile supplements
erectile issues in men over 50
2020/11/13 10:17:34
erectile supplements
is erectile dysfunction reversible
is erectile dysfunction a va disability rates
top erectile pills
cheapest erectile dysfunction pill comparison
2020/12/10 05:27:44
pharmaceutical viagra cialis levitra pens usacybes viagra vs cialis glicky Cialis Profesional England
2021/01/20 07:32:04
what is chloroquine
buy aralen
erectile prosthesis
erectile function
hydroxyquine medication
hydroxychloroquine sulfate tabs
erectile enhancement supplements
plaquenil therapy
side effects tadalafil
what is tadalafil
zirthomax
where can you buy zithromax