Forum Discussion
cjhoward18
7 years agoEmployee
Using Json generator I used this array of flattened docs:
from there I sort on product-id using sort snap,
then I groupBy product-id into a field called ‘group’:
Finally in the mapper I use this expression:
which generates an array of docs where each doc has ‘product-id’: [array of variants]:
If you need the output to look EXACTLY like you described you can use this expression instead of the one above: { “product-id” : $group[0][‘product-id’],“variants” :$group.reduce((accum, curval) => accum.concat([curval[‘variant’]]), )}
which will generate output exactly as you described: [{“product-id”:“1001”,“variants”:[“777101”,“777100”]},{“product-id”:“1002”,“variants”:[“777102”,“777103”,“777104”,“777105”]}]
Let me know if this answers your problem.