From fc874d901b15f45d16ae8902e2d8b53cd8bad595 Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Fri, 11 Mar 2022 20:08:08 -0800 Subject: [PATCH] jq: add filter array example (#7871) * Add filter array example * Remove 8th example --- pages/common/jq.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/common/jq.md b/pages/common/jq.md index 6aa86dc01..59213ddb4 100644 --- a/pages/common/jq.md +++ b/pages/common/jq.md @@ -11,6 +11,10 @@ `jq '.[]' {{file.json}}` +- Output elements from arrays which match provided filter: + +`jq '.[] | select(.{{key_name}} == {{value}})'` + - Read JSON objects from a file into an array, and output it (inverse of `jq .[]`): `jq --slurp . {{file.json}}` @@ -27,10 +31,6 @@ `cat {{file.json}} | jq '{{{my_new_key}}: .{{key_name}}, {{my_other_key}}: .{{other_key_name}}}'` -- Combine multiple filters: - -`cat {{file.json}} | jq 'unique | sort | reverse'` - - Output the value of a given key to a string (and disable JSON output): `cat {{file.json}} | jq --raw-output '"some text: \(.{{key_name}})"'`