informatique:jq
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
informatique:jq [03/10/2021 12:01] – créée 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:// | ||
- | * sur stackoverflow [[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 ' | ||
+ | | ||
+ | | .loans[].media[] | ||
+ | | select(.title==" | ||
+ | | {id: $m, title: .title} | ||
+ | ) | ||
+ | |group_by(.id)[] | ||
+ | |.[0] + { count: length } | ||
+ | ' members.json | ||
+ | </ | ||
informatique/jq.1633255275.txt.gz · Dernière modification : 03/10/2021 12:01 de cyrille