0
jqでフィルタリングしたい.jsonファイルがあります。そのオブジェクトのキー値が 'failed'の場合、配列全体を返します。どうすればいい?jqを使用してオブジェクトのキー値に基づいてArrayからオブジェクト全体を返します。
例のJSON:新しいファイルへ
"version": "0.26.0",
"controls": [{
"id": "os-1.0",
"status": "passed",
"code_desc": "File /etc/profile content should match /umask\\s*022/",
"profile_id": "test"
}, {
"id": "os-1.0",
"status": "passed",
"code_desc": "File /etc/bashrc content should match /umask\\s*022/",
"profile_id": "test"
}, {
"id": "os-1.0",
"status": "failed",
"code_desc": "File /etc/csh.cshrc content should match /umask\\s*022/",
"profile_id": "test"
"message": "\nexpected: \"/sbin/sulogin\"\n got: \n\n(compared using `cmp` matcher)\n"
}]
出力:JSONとして示さ
{
"id": "os-1.0",
"status": "failed",
"code_desc": "File /etc/csh.cshrc content should match /umask\\s*022/",
"profile_id": "test"
"message": "\nexpected: \"/sbin/sulogin\"\n got: \n\n(compared using `cmp` matcher)\n"
}
お試しください。https://github.com/stedolan/jq/wiki/Cookbook#filter-objects-based-on-the-contents-of-a-key –
@BhavinSolankiこれは私が試したことですこれまでのところ:cat file.json | jq -c '。[] | select(.controls |。and contains( "failure")) 'しかし、私は配列の座標が不足していると思います。 – hedda