stedolan/jq — pull request #450 by XavM (2014-06-27 07:57:09+00:00)
Title: Add jq builtin reduce_keys(f)

reduce_keys(.foo) takes as input an array of objects, and produces a single object with values added for a same key

Example :

jq 'reduce_keys(.)'
Input	[{"test-a": 1}, {"test-a": 2},{"test-a": 3},{"test-b": 4},{"test-b": 5}]
Output	{"test-a":6,"test-b":9}

jq 'reduce_keys(.)'
Input	[{"test-a": ["a"]}, {"test-a": ["b"]},{"test-a": ["c"]},{"test-b": ["x"]},{"test-b": ["y"]}]
Output	{"test-a":["a","b","c"],"test-b":["x","y"]}

jq 'reduce_keys(.)'
Input	[{"test-a": "a"}, {"test-a": "b"},{"test-a": "c"},{"test-b": "x"},{"test-b": "y"}]
Output	{"test-a":"abc","test-b":"xy"}