1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-06-06 10:46:00 +02:00
tldr/pages/common/jq.md

28 lines
564 B
Markdown
Raw Normal View History

2016-12-21 18:40:12 -05:00
# jq
> A lightweight and flexible command-line JSON processor.
- Output JSON file:
`cat {{file}} | jq`
- Output all elements from JSON array in file, or all key-value pairs from JSON objects in file:
`cat {{file}} | jq .[]`
- Read JSON objects from file, into array, and output (inverse of `jq .[]`):
`cat {{file}} | jq --slurp`
- Output first element in JSON file:
`cat {{file}} | jq .[0]`
- Output "key" of first element in JSON file:
`cat {{file}} | jq .[0].{{key}}`
- Output "key" of each element in JSON file:
`cat {{file}} | jq 'map(.{{key}})'`