the dataweave script i tried is throwing an error that says i have to first transform the data into an array using then concert to a json object.It’s returning null instead of the values.
INPUT:
id;email;phone;Fname;Lname
154784;[email protected];0123456789;omd;lamia
MY CODE:
%dw 2.0
output application/json
---
payload map (item, index) -> {
id: item.id,
email: item.email,
phone: item.phone,
Fname: item.Fname`
Lname: item.Lname
}
OUTPUT:
[
{
"id": null,
"email": null,
"phone": null,
"Fname": null,
"Lname": null
}
]
2
Answers
You must tell DataWeave that it is a CSV but separated by a semicolon instead of a comma. If it is a Mule application the preferred solution is by setting the output type reader properties at the component that creates that payload. In Mule 4.x you can do that by using the
outputMimeType
attribute of connectors. Reader properties are configured after the format".For example if you read the CSV from a Mule 4 file connector you can set the separator character like this:
After setting the separator character it should work.
If for some reason you can not change the output type at the source you can do it in the flow using
<set-payload>
.