informatique:jq
Ceci est une ancienne révision du document !
Table des matières
jq
- Pour faire des requêtes en ligne : https://jqplay.org
Play with js
members.json:
[
{
"member_id": 123,
"loans":[
{
"date": "123",
"media": [
{ "title": "foo" },
{ "title": "bar" }
]
},
{
"date": "456",
"media": [
{ "title": "foo" }
]
}
]
},
{
"member_id": 456,
"loans":[
{
"date": "789",
"media": [
{ "title": "foo"}
]
}
]
}
]
Howto count occurrence of "grouped by key" with jq?
No need to use group_by → https://stackoverflow.com/questions/69423726/howto-count-occurrence-of-grouped-by-key-with-jq/69423860#69423860
"foo" as $title | .[] | {
id: .member_id,
$title,
count: [.loans[].media[] | select(.title == $title)] | length
}
{
"id": 123,
"title": "foo",
"count": 2
}
{
"id": 456,
"title": "foo",
"count": 1
}
informatique/jq.1633257745.txt.gz · Dernière modification : de cyrille
