diff --git a/pages/common/jq.md b/pages/common/jq.md index 23891560a6..a480ea9114 100644 --- a/pages/common/jq.md +++ b/pages/common/jq.md @@ -4,24 +4,24 @@ - Output a JSON file, in pretty-print format: -`cat {{file}} | jq` +`jq . {{file.json}}` - Output all elements from arrays (or all key-value pairs from objects) in a JSON file: -`cat {{file}} | jq .[]` +`jq .[] {{file.json}}` - Read JSON objects from a file into an array, and output it (inverse of `jq .[]`): -`cat {{file}} | jq --slurp` +`jq --slurp . {{file.json}}` - Output the first element in a JSON file: -`cat {{file}} | jq .[0]` +`jq .[0] {{file.json}}` -- Output the value of a given key of the first element in a JSON file: +- Output the value of a given key of the first element in a JSON from stdin: -`cat {{file}} | jq .[0].{{key_name}}` +`cat {{file.json}} | jq .[0].{{key_name}}` -- Output the value of a given key of each element in a JSON file: +- Output the value of a given key of each element in a JSON from stdin: -`cat {{file}} | jq 'map(.{{key_name}})'` +`cat {{file.json}} | jq 'map(.{{key_name}})'`