jq is a lightweight and flexible command-line JSON processor.
https://stedolan.github.io/jq/| Installer Source| Releases (json) (tab)
jq is a lightweight and flexible command-line JSON processor.
https://stedolan.github.io/jq/| Installer Source| Releases (json) (tab)
To update or switch versions, run webi jq@stable
(or @v1.6
, @beta
, etc).
These are the files / directories that are created and/or modified with this install:
~/.config/envman/PATH.env
~/.local/bin/jq
jq
is likesed
for JSON data - you can use it to slice and filter and map and transform structured data with the same ease thatsed
,awk
,grep
and friends let you play with text.
All jq selectors begin with .
- don't forget that!
Be sure to checkout the official tutorial and jq manual for more info.
You can also try online.
echo '{ "name": "foo" }' | jq '.name'
"foo"
The -r
or --raw-output
flag unwraps strings:
echo '{ "name": "foo" }' | jq -r '.name'
foo
echo '{ "name": "foo" }' | jq '.'
{
"name": "foo"
}
echo '[ { "name": "foo" } ]' | jq '.[0]'
{
"name": "foo"
}
echo '[ { "name": "foo" } ]' | jq -r '.[0].name'
foo
echo '[ { "name": "foo" }, { "name": "bar" } ]' \
| jq -r '.[].name'
foo
bar
Anything that doesn't start with a .
is part of the transformation template.
Anything that collects starts with .[]
.
Anything that transforms has a pipe and selector | .whatever
.
Be sure to checkout the official tutorial and jq manual for more info.
echo '[ { "name": "foo", "age": 0 }, { "name": "bar", "age": 2 } ]' \
| jq '{ names: [.[] | .name], ages: [.[] | .age] }'
{
"names": [
"foo",
"bar"
],
"ages": [
0,
2
]
}