Parentheses in JQ for .key

后端 未结 1 1922
孤城傲影
孤城傲影 2020-12-11 22:05

I don\'t understand why key has to be in () for this to work:

# kbrandt at glade.local in ~ on git:master x [15:08:19]
$ cat host | jq \'. | to_         


        
相关标签:
1条回答
  • 2020-12-11 22:51

    When defining an object literal, the parentheses indicates that the expression value should be the property name. Otherwise if you didn't use parentheses, it's the literal name.

    So these are equivalent ways to define an object with a "foo" property:

    { foo: 1 }
    { "foo": 2 }
    "foo" as $name | { ($name): 3 }
    { somename: "foo" } | { (.somename): 4 }
    
    0 讨论(0)
提交回复
热议问题