5 Dataweave CSV Use Cases for your next integration
There are times where some integrations require data to be read or written as comma separated values or csv. To do so, Dataweave offers a csv format. Read along to review some CSV fundamentals in Dataweave.
This tutorial will use two previously read CSV files. One is stored as payload, while the other is stored in a variable called newFile.
FirstName, LastName, Age Whitney, George, 20 Cheryl, Gold, 25 Jeanette, Godwin, 30
Variable - newFile:
FirstName, LastName, Age Monica, Good, 35 Gabby, Gates, 25 Stephanie, Gaines, 40
Use Case 1: Retrieve all values in a column.
Example: Retrieve a list of FirstNames.
Use Case 2: Access a row (record) of information
Example: Access the first row
Notice: Each row is an object of key: value pairs
Use Case 3: Concatenate two csv formatted files
Example: Two files stored in memory are concatenated. One is stored as a payload and one is stored as a variable called newFile.
Notice: This example was done in Dataweave Playground. Inside studio you would access variables using vars.<variable_name>.
%dw 2.0 output application/csv --- payload ++ vars.newFile
Use Case 4: Convert as String
Example: You want to log the payload as a string.
Consider streaming read operations.
For more information regarding csv files, check out the CSV format MuleSoft documentation: