| name | jq-processing |
| description | Using jq to parse, filter, and aggregate JSON data from CLI tools for generating reports. |
jq for JSON Processing
Basics
jq '.' - pretty-print JSON
jq '.field' - extract a field
jq 'length' - count array elements
jq '[.[] | select(.cond)]' - filter arrays
Date Handling
echo '"2024-12-15T10:30:00Z"' | jq 'fromdateiso8601'
jq -n '("2024-12-20T00:00:00Z" | fromdateiso8601) - ("2024-12-15T00:00:00Z" | fromdateiso8601) | . / 86400'
Rounding
jq -n '3.14159 * 10 | round / 10'
Building Final JSON
jq -n \
--argjson pr_total 50 \
--argjson pr_merged 40 \
--arg top "user1" \
'{
pr: { total: $pr_total, merged: $pr_merged, top_contributor: $top }
}'
Label Matching (substring check)
echo "$issues_json" | jq '
[.[] | select(.labels | any(.name | test("bug"; "i")))]
'