$ echo '[{"name": "Elvis", "age": 25}, {"name": "Bruna", "age": 22}]' | jq -r '.[] | [.name, .age] | @csv'
"\"Elvis\",25"
"\"Bruna\",22"
$ echo '[{"name": "Maria"}, {"name": "John"}]' | jq '.[]'
{
"name": "Maria"
}
{
"name": "John"
}
$ echo '[{"name": "Maria"}, {"name": "John"}]' | jq '.[]' | jq -s '.'
[
{
"name": "Maria"
},
{
"name": "John"
}
]
cat comentarios-canal-2021-05-22.json | jq '.[].items | .[]?.snippet.topLevelComment.snippet' | less
skins.json
[{
"hash": "Glock-18 | Water Elemental (Minimal Wear)",
"price": "4.4700",
"float": "0.11328461",
"sold": "2019-03-09T09:40:26-03:00"
},
{
"hash": "Glock-18 | Water Elemental (Minimal Wear)",
"price": "4.1100",
"float": "0.12572628",
"sold": "2019-03-09T08:17:49-03:00"
}]
cat skins.json | jq -r '.[] | "\(.price), \(.sold)"'
echo '[{"foo":10, "bar":200}]' | jq '.[] | {age: .foo}'
echo '{ "host" : "1", "user" : "root", "private_key" : "x" }' | jq 'keys'
[
"host",
"private_key",
"user"
]
echo '{ "host" : "1", "user" : "root", "private_key" : "x" }' | jq 'keys|length'
3
echo '{ "host" : "1", "user" : "root", "private_key" : "x" }' | jq 'keys|.[0:2]'
[
"host",
"private_key"
]
echo '{"name": "Elvis"}' | jq '.name[2:]'
vis
$ json='[{"genre":"deep house"}, {"genre": "progressive house"}, {"genre": "dubstep"}]' &&\
echo "$json" | jq '.[] | select(.genre | contains("house"))'
{"genre":"deep house"}
{"genre":"progressive house"}
# or
$ echo "$json" | jq '[ .[] | select( .genre | contains("house")) ]'
[{"genre":"deep house"},{"genre":"progressive house"}]
# or
$ echo "$json" | jq 'map(select(.genre | contains("house")))'
[{"genre":"deep house"},{"genre":"progressive house"}]
echo '{"name":"some-name" ,"value":"[{\"hashName\":\"★ Bayonet\"}]","timestamp":1531335404,"status":200}' | jq -r '.value' | jq '.'
echo '{"value": "{\"name\": 12}" }' | python -c 'import sys, json; print json.load(sys.stdin)["value"]' | python -m json.tool
$ echo '[
{ "title": "My Title 2", "metadata": "{\"name\": \"Grape\"}" },
{ "title": "My Title", "metadata": "{\"name\": \"Orange\"}" }
]' | jq '.[] | { "title": .title, metadata: .metadata | fromjson }'
{
"title": "My Title 2",
"metadata": {
"name": "Grape"
}
}
{
"title": "My Title",
"metadata": {
"name": "Orange"
}
}
export APP_VERSION=1.0
export DESC='some "desc'
export CURRENT_BRANCH=master
echo '{}' | jq --arg tag_name "$APP_VERSION" \
--arg target_commitish "$CURRENT_BRANCH" \
--arg body "$DESC" '{
$tag_name,
$target_commitish,
name: $tag_name,
$body,
"draft": false,
"prerelease": true
}'
How to use jq