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
)