โ11-05-2021 08:46 AM
Hi All,
How to achieve this in snaplogic . I tried using different snaps like joiner,union,group by , but none is giving desired output.
Input:
[
{
โfilenameโ: โa1.datโ,
},
"filename": "a2.dat",
},
{
โcountโ: 2,
โtypeโ: โpdfโ
}
]
expected output is:
[
{
โfilenameโ: โa1.datโ,
โcountโ: 2,
โtypeโ: โpdfโ
},
"filename": "a2.dat",
"count": 2,
"type": "pdf"
}
]
โ11-05-2021 09:13 AM
Hi @kkishore,
This can be done with the Group by N snap, but first I need to know if we can always expect the
{ "count": 2, "type": "pdf" }
object to be the last element in the input ?
โ11-05-2021 08:15 PM
Hi @j.angelevski,
It is not same, it changes like { โcountโ:54, โtypeโ: โexcel sheetโ} or { โcountโ:72, โtypeโ: โwordโ} .
depending on the source it varies.
โ11-06-2021 10:48 AM
@kkishore, assuming that the last object will be in the format that you provided, you can implement the following solution.
'count'
object to each input document.$group.filter(val => val.get("count") == null).map(val => val.extend($group[$group.length - 1]))
Target path: $array
Result:
{
"array": [
{
"filename": "a1.dat",
"count": 2,
"type": "pdf"
},
{
"filename": "a2.dat",
"count": 2,
"type": "pdf"
}
]
}
After this, you can use a JSON Splitter if you want to split the array.
โ11-08-2021 05:43 AM
Hi @j.angelevski ,
Thanks for the response and it is working as expected.