Ich habe eine JSON-Datei, die ich durch jq filtern möchte, um das gesamte Objekt im Array zurückzugeben, wenn der Schlüsselwert in diesem Objekt "gescheitert" ist. Wie würde ich das tun?Zurückgeben des gesamten Objekts aus Array basierend auf Schlüsselwert im Objekt mithilfe von jq
Beispiel 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"
}]
Ausgabe in eine neue Datei:
{
"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"
}
können Sie bitte versuchen https://github.com/stedolan/jq/wiki/Cookbook#filter-objects-based-on-the-contents-of-a-key –
@ BhavinSolanki Dies ist, was ich versucht habe Bisher: cat file.json | jq -c '. [] | Wählen Sie (.controls |. und enthält ("failure")) 'aber ich glaube, ich vermisse eine Array-Koordinate – hedda