3 homepage: https://stedolan.github.io/jq/
5 jq is a lightweight and flexible command-line JSON processor.
7 `jq` is like `sed` for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that `sed`, `awk`, `grep` and friends let you play with text.
10 All jq selectors begin with `.` - don't forget that!
12 Be sure to checkout the
13 [official tutorial](https://stedolan.github.io/jq/tutorial/) and
14 [jq manual](https://stedolan.github.io/jq/manual/) for more info.
16 You can also [try online](https://jqplay.org/).
18 ### How to select a single a property from an object
21 echo '{ "name": "foo" }' | jq '.name'
28 ### How to remove quotes from strings
30 The `-r` or `--raw-output` flag unwraps strings:
33 echo '{ "name": "foo" }' | jq -r '.name'
40 ### How to select a whole object
43 echo '{ "name": "foo" }' | jq '.'
52 ### How to select an element from an array
55 echo '[ { "name": "foo" } ]' | jq '.[0]'
64 ### How to select a single property from an array element
67 echo '[ { "name": "foo" } ]' | jq -r '.[0].name'
74 ### How to select some properties from multiple elements
77 echo '[ { "name": "foo" }, { "name": "bar" } ]' \
86 ### How transform or zip an array
88 Anything that doesn't start with a `.` is part of the transformation template.
90 Anything that collects starts with `.[]`.
92 Anything that transforms has a pipe and selector `| .whatever`.
94 Be sure to checkout the
95 [official tutorial](https://stedolan.github.io/jq/tutorial/) and
96 [jq manual](https://stedolan.github.io/jq/manual/) for more info.
99 echo '[ { "name": "foo", "age": 0 }, { "name": "bar", "age": 2 } ]' \
100 | jq '{ names: [.[] | .name], ages: [.[] | .age] }'