Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#jq コマンドで結果が空配列の場合に何も出力しない例 #981

Open
YumaInaura opened this issue Mar 29, 2019 · 0 comments
Labels

Comments

@YumaInaura
Copy link
Owner

問題

空配列がそのまま標準出力されてしまう。

$ echo '[]' | jq '.'
[]

解決

$ echo '[]' | jq 'select(length > 0)'

配列の中身があっても大丈夫

$ echo '[1,2,3]' | jq 'select(length > 0)'
[
  1,
  2,
  3
]

ダメな例

以下の書き方だと中身がある場合に配列が崩れてしまう。

$ echo '[1,2,3]' | jq '.[]'
1
2
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant