【发布时间】:2020-07-09 16:21:37
【问题描述】:
我有一个返回大量对象数组的调用。
对象看起来像:
{
"accounts": [
{
"id": 1234,
"name": "Sample Name",
"status": "upgraded",
"subscription": {
"id": 4567,
"products": [
{
"product_id": 5,
"name": "Awesome Product",
"units": 1,
"price": 1
},
{
"product_id": 1,
"name": "Another Awesome Product",
"units": 1,
"price": 1
}
]
},
"owner": {
"id": 12345,
"email": "email@email.com",
"first_name": "John",
"last_name": "Doe",
"state": "active"
}
}
]
}
在这个数组中,有很多不同的对象,有很多不同的所有者,我想返回一个只包含id(对象的第一个属性)如果所有者的数组em> 属性是 12345。
目前为止
| jq -r '.accounts[] | [.id]'
它返回对象中的所有“id”,但我无法根据“所有者”值过滤此数组
我已经尝试添加:
| jq -r '.accounts[] | [.id] | select(.id == 12345)'
但我目前遇到了错误
Cannot index array with string "id"
【问题讨论】:
-
抱歉,accounts 是 root 密钥 - 我发布的所有内容都在 accounts 密钥中