cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a property name to my incoming Array

bcole
New Contributor

How to I add a property name to my incoming array: Looks this way:
[{
“fileName”: “Invoice.pdf”,
“filePath”: “\\Server01\FileFolder\12575\773016951\6b83566e-0908-42f9-9bbe-9adefb296633”
},
{
“fileName”: “Invoice2.pdf”,
“filePath”: “\\Server01\FileFolder\12575\773016951\6b83566e-0908-42f9-9bbe-adefb296633”
}
]
I need it to look like the following after transformation:
“Document”: {
“Documents”: [{
“fileName”: “Invoice.pdf”,
“filePath”: “\\Server01\FileFolder\12575\773016951\6b83566e-0908-42f9-9bbe-9adefb296633”
},
{

            "fileName": "Invoice2.pdf",
            "filePath": "\\\\Server01\\FileFolder\\12575\\773016951\\6b83566e-0908-42f9-9bbe-9adefb296633"
        }
    ]
}

}
How do I accomplish that?

1 REPLY 1

Supratim
Contributor III

Hi @bcole , Lets assume the documents array you save as documents_array variable. Then you can use below expression in next snap and if you want can make target field as $.(if you want to pass other data then don’t use $)

{
“Document”:{
“Documents”: sl.ensureArray($documents_array)
}
}

If you want to avoid extra mapper, then your can use below
{
“Document”:{
“Documents”: sl.ensureArray(your logic to get documents)
}
}