informatique:jq
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| informatique:jq [03/10/2021 12:11] – cyrille | informatique:jq [04/10/2021 08:40] (Version actuelle) – [jq] cyrille | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== jq ====== | ====== jq ====== | ||
| - | [[https:// | + | **[[https://stedolan.github.io/jq/|jq]]** a lightweight and flexible command-line JSON processor. |
| + | * Le [[https:// | ||
| * La [[https:// | * La [[https:// | ||
| * Le [[https:// | * Le [[https:// | ||
| + | * Pour faire des requêtes en ligne : https:// | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | |||
| + | |||
| + | ===== Play with jq ===== | ||
| + | |||
| + | '' | ||
| + | < | ||
| + | [ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { " | ||
| + | { " | ||
| + | ] | ||
| + | }, | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { " | ||
| + | ] | ||
| + | } | ||
| + | ] | ||
| + | }, | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { " | ||
| + | ] | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | ] | ||
| + | </ | ||
| + | |||
| + | ==== Howto count occurrence of " | ||
| + | |||
| + | https:// | ||
| + | |||
| + | === Sans group_by === | ||
| + | |||
| + | <code bash> | ||
| + | jq '" | ||
| + | id: .member_id, | ||
| + | $title, | ||
| + | count: [.loans[].media[] | select(.title == $title)] | length | ||
| + | }' members.json | ||
| + | </ | ||
| + | < | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Avec group_by === | ||
| + | |||
| + | <code bash> | ||
| + | jq 'map( | ||
| + | | ||
| + | | .loans[].media[] | ||
| + | | select(.title==" | ||
| + | | {id: $m, title: .title} | ||
| + | ) | ||
| + | |group_by(.id)[] | ||
| + | |.[0] + { count: length } | ||
| + | ' members.json | ||
| + | </ | ||
informatique/jq.1633255864.txt.gz · Dernière modification : de cyrille
