我正在嘗試決議這個 json,以便我可以從輸入中提取所有字典,其中“uri”欄位不以字串“/themes”開頭
{
"version": 0,
"permissionMask": 2,
"creationDate": "2022-06-09T14:42:41",
"updateDate": "2021-11-17T06:48:52",
"label": "webPageView.css",
"uri": "/themes/default/webPageView.css",
"resourceType": "file"
},
{
"version": 0,
"permissionMask": 2,
"creationDate": "2022-06-09T14:42:43",
"updateDate": "2021-11-17T06:48:48",
"label": "[email protected]",
"uri": "/internal/default/images/[email protected]",
"resourceType": "file"
}
所以輸出只包含
{
"version": 0,
"permissionMask": 2,
"creationDate": "2022-06-09T14:42:43",
"updateDate": "2021-11-17T06:48:48",
"label": "[email protected]",
"uri": "/internal/default/images/[email protected]",
"resourceType": "file"
}
我試過了
jq -r '.[] | select( .[].uri | ( startswith( "/themes" ) | not ) )'
但這似乎不起作用。它只是轉儲所有輸出而不過濾掉 uri 欄位以“/themes”開頭的字典
uj5u.com熱心網友回復:
假設物件在一個陣列中
.[] | select(.uri | startswith( "/themes" ) | not)
給
{
"version": 0,
"permissionMask": 2,
"creationDate": "2022-06-09T14:42:43",
"updateDate": "2021-11-17T06:48:48",
"label": "[email protected]",
"uri": "/internal/default/images/[email protected]",
"resourceType": "file"
}
在線嘗試
關于您的過濾器,不需要.[].uri內部,select()因為第一個.[]已經在陣列上回圈,所以.內部select()指的是物件本身。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490932.html
