mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-08-07 05:35:43 +02:00
jq: Accepts a file as last parameter
Examples look simpler with file as last parameter than with using `cat`, also they explicitly show that you must use `.` as the default all-matching rule. Keep the last two examples with piping, and change their descriptions accordingly.
This commit is contained in:
parent
d44081fdd3
commit
a2d755a504
1 changed files with 8 additions and 8 deletions
|
@ -4,24 +4,24 @@
|
||||||
|
|
||||||
- Output a JSON file, in pretty-print format:
|
- 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:
|
- 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 .[]`):
|
- 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:
|
- 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}})'`
|
||||||
|
|
Loading…
Add table
Reference in a new issue