我从命令中获得以下JSON输出。
[
{
"userId": "abc@xyz.com",
"firstname": "Tyrion",
"lastname": "Lannister",
"state": "ACTIVE"
},
{
"userId": "def@xyz.com",
"firstname": "Jamie",
"lastname": "Lannister",
"state": "ACTIVE"
},
{
"userId": "ghi@xyz.com",
"firstname": "Cersi",
"lastname": "Lannister",
"state": "ACTIVE"
}
]
当我尝试使用以下内容选择userId
时
<command> | jq '.[] | select ('firstname')
我收到以下错误
jq: error: userId/0 is not defined at <top-level>, line 1:
.[] | select (userId)
jq: 1 compile error
但是,如果我将输出保存到文件中
jq '[] | .firstname' lannisters.json
我知道
"Tyrion"
"Jamie"
"Cersi"
在zsh中失败时为什么文件版本起作用的任何指针吗?