79279866

Date: 2024-12-14 00:37:20
Score: 1.5
Natty:
Report link

Okay, so I guess posting the question is all I needed to find the answer. The answer was a combination of

reduce($$ ++ $)

which helped reduce the array of key/value pairs down into a single JSON object

and putting the proper parens() around the functions to include both the fieldMappings and the reduce

and then being able to put the as Object after the reduce, but before the end of the function that spits out the array of objects

Makes sense when I really think about it, but I'm new to DataWeave script and so the notion of nested functions isn't something I am familiar with.

Anyway, for those interested here is what worked:

%dw 2.0
input csvData application/csv
input fieldMappings application/json
input objectProperties application/json
var apexClass = objectProperties.ObjectName

output application/apex
---

csvData map ((row) ->
    (
        (
        fieldMappings map (fieldMapping) ->
        (fieldMapping.target) : if(row[fieldMapping.source] != "") row[fieldMapping.source] else fieldMapping."defaultValue"
        )
        reduce ($$ ++ $)
    ) as Object
)
Reasons:
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (1.5): I'm new
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: caleb