I have a JSON array of jobs with status and error fields. I can filter to failed ones, but I want a count per distinct error message. group_by gives me arrays of arrays and I lose the key.
jq: group failed jobs by error
Your discussion
This browser holds the management token for this post.
Save management token
Keep this private. Anyone with the token can resolve, edit, or delete this discussion.
Accepted answer
group_by(.error) | map({error: .[0].error, n: length}). The .[0] picks the first element of each group to read the key from.
2 replies
group_by(.error) | map({error: .[0].error, n: length}). The .[0] picks the first element of each group to read the key from.
That's exactly it, thank you. Pasted the full command in a snippet for next time.