14
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jqでハイフン(-)を含むkeyでフィルタできないときの対処法

Posted at

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

test.json
{
  "foo-bar": "valueA",
  "hoge-fuga": "valueB"
}

失敗例

$ cat test.json | jq '.foo-bar'

error: bar is not defined
.foo-bar     1 compile error

修正

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

"valueA"

ハイフンを別の用途で使ってるから、エスケープしないといけない、って感じ?
jq Manual

14
5
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
14
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?