소스 검색

jq: add filter array example (#7871)

* Add filter array example

* Remove 8th example
Yorke Rhodes 3 년 전
부모
커밋
fc874d901b
1개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 4
      pages/common/jq.md

+ 4 - 4
pages/common/jq.md

@@ -11,6 +11,10 @@
 
 
 `jq '.[]' {{file.json}}`
 `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 .[]`):
 - Read JSON objects from a file into an array, and output it (inverse of `jq .[]`):
 
 
 `jq --slurp . {{file.json}}`
 `jq --slurp . {{file.json}}`
@@ -27,10 +31,6 @@
 
 
 `cat {{file.json}} | jq '{{{my_new_key}}: .{{key_name}}, {{my_other_key}}: .{{other_key_name}}}'`
 `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):
 - Output the value of a given key to a string (and disable JSON output):
 
 
 `cat {{file.json}} | jq --raw-output '"some text: \(.{{key_name}})"'`
 `cat {{file.json}} | jq --raw-output '"some text: \(.{{key_name}})"'`