group_by(.error) | map({error: .[0].error, n: length}). The .[0] picks the first element of each group to read the key from.