Forum Discussion
tlikarish
5 years agoEmployee
Hi chrisbodman,
If I understand your problem, you’re looking to take the output of a Group By Fields and flatten the grouping into a single object?
So in your example, this
{Id:1, Roof:true}, {Id:1, doors:true}
becomes
{Id:1, Roof:true, doors:true}
If that’s the case, than you could use this expression in a mapper.
jsonPath($, "$group[*]").reduce((accum, o) => accum.extend(o), {})
Essentially you’re doing a reduce
on the array to build a new object as the result. Here’s a break down of how it works:
-
jsonPath($, "$group[*]")
get the elements underneath $group -
reduce((accum, o) => ..., {})
reduce the array of objects into a single object{}
-
accum.extend(o)
for each object in the array, extend the accumulating object with its members
Here’s a pipeline example you can use to play around with it. Let me know if this works.
reduce-example_2021_03_18.slp (4.7 KB)