jq 'group_by(.dept) | map({dept: .[0].dept, total: map(.salary) | add})' data.json

Category: Data Science & Analysis

jq 'group_by(.dept) | map({dept: .[0].dept, total: map(.salary) | add})' data.json

Sum salaries per department with jq

jq is a JSON processor built around a pipeline of filters. Here group_by(.dept) buckets objects by department, then map builds one summary object per bucket, adding all salary values with add. The pipe symbol (|) chains filters, feeding each stage's output into the next. This is the jq equivalent of a SQL GROUP BY with SUM.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.