3
2

More than 5 years have passed since last update.

jqのハイフン(-)を含むkeyでフィルタ出来ない件の対応

Last updated at Posted at 2018-11-26

偉大なる元記事: jqでハイフン(-)を含むkeyでフィルタできないときの対処法

$ cat test.json | jq '.["foo-bar"]'

これが動かなかったので調べ直しになってしまった。
MacbookProに入れたjqが新しい、もしくは古いので非サポートになったのかな?

$ jq --help
jq - commandline JSON processor [version 1.5]

詳しくは
Github: Cannot select field if field name has dashes #38

元記事にリンクが張ってあるので確認、

hexsel commented on 25 Mar 2016
Just for posterity, the following seems to work:
jq .\"a-b\"
Seems like the shortest working query string with a hyphen.

どれどれ、実際にjqの1.5で確かめてみたところ、
'."key-of-path"'で値を抜き出す事に成功。
1.5以降のバージョンの人はこちらも試してみてね。

3
2
1

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