mulesoft – JSON File to Salesforce Object, e.g. using For Each block
I tried to figure out how to get the following JSON object as Mulesoft Payload:
[
{
“FileType”: “pdf”,
“FileName”: “FilenameOfPdf”,
“FileContent”: “AnyFilecontentOfPdf”
},
{
“FileType”: “txt”,
“FileName”: “FilenameOfTxt”,
“FileContent”: “FileContentOfTxt”
},
{
“FileType”: “xml”,
“FileName”: “FilenameOfXml”,
“FileContent”: “FileContentOfXml”
}
]
Here’s the above-mentioned JSON as an image: 
In need this in a form to make at the end the following Salesforce Create call:
output application/java
{
XML__c : <theDataStoredInXML’sFileContent>
PDF__c : <theDataStoredinPDF’sFileContent>
TXT__c : <theDataStoredinTXT’sFileContent>
}
My idea was to (using a For Each block) through the JSONfile and write a new csv file (all blocks in APPEND mode, such that only in the first iteration a csv-File is created) that has conditions e.g. if payload.FileType == “pdf” then write PDF: payload.FileContent and if payload.FileType == “txt” then write TXT: payload.FileContent and the same for the third parameter such that in the end I have the csv table:
PDF,<theDataStoredinPDF’sFileContent>
XML, <theDataStoredinXML’sFileContent>
TXT, <theDataStoredinTXT’sFileContent>
in mir For-Each-Write-Block the following is written:
The problem is, when I make these writes using the append function I just get the data “underneath” no so file to be opened as csv or xlsx
Any help or question/idea is very much appreciated! Also an idea how to handle the data without having to store it in between as a csv or xlsx would be great!
Best regards,
Lukas
Read more here: Source link


