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.