[英]How to filter arrays in json based on specific value using jq
我正在嘗試使用jq進行過濾,以過濾此json中的數組,以僅獲取具有“ policy_id”:199383的數組,並排除包含不同policy_id值的數組。
{
"links": {
"policy_id": 199383,
"violations": [
69892478
]
},
"incident_preference": "PER_CONDITION_AND_TARGET",
"closed_at": 1519408001909,
"opened_at": 1519407125437,
"id": 17821334
}
{
"links": {
"policy_id": 199383,
"violations": [
69889831
]
},
"incident_preference": "PER_CONDITION_AND_TARGET",
"closed_at": 1519408011851,
"opened_at": 1519406230858,
"id": 17820349
}
{
"links": {
"policy_id": 194774,
"violations": [
68446755
]
},
"incident_preference": "PER_POLICY",
"closed_at": 1518835775531,
"opened_at": 1518835745303,
"id": 17422347
}
{
"links": {
"policy_id": 199383,
"violations": [
69892488
]
},
"incident_preference": "PER_CONDITION_AND_TARGET",
"closed_at": 1519402345676,
"opened_at": 1519401235467,
"id": 17821334
}
我試過了:jq'.incidents [] | 選擇(.links.policy_id ==“ 199383”)'file.json。 但是沒有任何回報嗎? 誰能幫忙。
謝謝
jq '.incidents[]| select(.links.policy_id==199383)' file.json
應該這樣做。
輸出量
{
"links": {
"policy_id": 199383,
"violations": [
69892478
]
},
"incident_preference": "PER_CONDITION_AND_TARGET",
"closed_at": 1519408001909,
"opened_at": 1519407125437,
"id": 17821334
}
{
"links": {
"policy_id": 199383,
"violations": [
69889831
]
},
"incident_preference": "PER_CONDITION_AND_TARGET",
"closed_at": 1519408011851,
"opened_at": 1519406230858,
"id": 17820349
}
{
"links": {
"policy_id": 199383,
"violations": [
69892488
]
},
"incident_preference": "PER_CONDITION_AND_TARGET",
"closed_at": 1519402345676,
"opened_at": 1519401235467,
"id": 17821334
}
來自json.org
字符串是零個或多個Unicode字符的序列,使用反斜杠轉義符將其括在雙引號中 。 字符表示為單個字符串。 字符串非常類似於C或Java字符串。)
和
除了不使用八進制和十六進制格式外,數字與C或Java數字非常相似。
因此199383
與"199383"
明顯不同。 它們分別是數字和字符串。
注意:引用文字中的重點是我的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.