Count By Property

Count occurrences of array elements grouped by a specified property.

Code

General
echo "$arr" | jq --arg k "$key" 'group_by(.[$k]) | map({(.[0][$k]): length}) | add'

Parameters

Array of objects (JSON)

Property to count by

Server

More Bash Snippets