3 homepage: https://stedolan.github.io/jq/
5 jq is a lightweight and flexible command-line JSON processor.
8 To update or switch versions, run `webi jq@stable` (or `@v1.6`, `@beta`, etc).
12 > `jq` is like `sed` for JSON data - you can use it to slice and filter and map
13 > and transform structured data with the same ease that `sed`, `awk`, `grep` and
14 > friends let you play with text.
16 All jq selectors begin with `.` - don't forget that!
18 Be sure to checkout the
19 [official tutorial](https://stedolan.github.io/jq/tutorial/) and
20 [jq manual](https://stedolan.github.io/jq/manual/) for more info.
22 You can also [try online](https://jqplay.org/).
24 ### How to select a single a property from an object
27 echo '{ "name": "foo" }' | jq '.name'
34 ### How to remove quotes from strings
36 The `-r` or `--raw-output` flag unwraps strings:
39 echo '{ "name": "foo" }' | jq -r '.name'
46 ### How to select a whole object
49 echo '{ "name": "foo" }' | jq '.'
58 ### How to select an element from an array
61 echo '[ { "name": "foo" } ]' | jq '.[0]'
70 ### How to select a single property from an array element
73 echo '[ { "name": "foo" } ]' | jq -r '.[0].name'
80 ### How to select some properties from multiple elements
83 echo '[ { "name": "foo" }, { "name": "bar" } ]' \
92 ### How transform or zip an array
94 Anything that doesn't start with a `.` is part of the transformation template.
96 Anything that collects starts with `.[]`.
98 Anything that transforms has a pipe and selector `| .whatever`.
100 Be sure to checkout the
101 [official tutorial](https://stedolan.github.io/jq/tutorial/) and
102 [jq manual](https://stedolan.github.io/jq/manual/) for more info.
105 echo '[ { "name": "foo", "age": 0 }, { "name": "bar", "age": 2 } ]' \
106 | jq '{ names: [.[] | .name], ages: [.[] | .age] }'