I see summing value in an array of maps and wonder if there is an elegant way in jq to perform a general recursion over a set of objects and sum all values they contain to produce a single output object as the sum of all the other objects.
If it is easier to do this over a single input object which wraps all the other objects (to avoid slurping), that is fine too.
- recurse over a slurped series of independent objects which have a lot of arbitrary nesting (arbitrary in the sense that I don't want to have to code jq for the specifics of the hierarchy of objects if general recursion can do what I want), and
- sum every numeric value of a key:value pair found at any level
Each object can have be sparse, but all coincident object key paths should sum their values to the same location in the single output object hierarchy.
For example (wrap an array around these 3 objects if that makes it easier):
{ A { B { x:1, y:4 }, C { x:3, z:6 }, t:2 }, s:5 }
{ A { B { x:2 , z:3 }, t:1 } }
{ A { , C { y:3, z:2 } }, s:3 }
would produce
{ A { B { x:3, y:4, z:3 }, C { x:3, y:3, z:8 }, t:3 }, s:8 }