11_DataWeave Flashcards
By default, where is the dataweave code?
inline in the Mule configuration file
Where is sample data used for live preview stored?
src/test/resources
Where are the dwl files stored?
src/main/resources
dwl stand for?
data weave language
Where in the Transform Message component can you reference to use an external DWL file?
resource attribute
Where in an element that has an expression property (e.g. choice router), can you use reference to an external DWL file?
using syntax ${file::filename}
Can you create modules (libraries) of reusable Dataweave functions?
yes
How do you create multiple transformations with one Transform Message Component?
- Add new target button (lines and a plus sign), 2. Set where to store result (Variables or Attributes or…) 3. Switch between multiple transformation (click on the dropdown.
The data model of the produced output of the dataweave expression could consist of what 3 data types?
Object. Array. Simple literals.
What is an object?
Key : value pairs.
What is an Array?
A sequence of comma separated values.
How is a dataweave expression separated into header and body?
Delimiter to separate header and body
What does the header of a dwl file contain?
directives that apply to the body expression
What does the body of a dwl file contain?
DataWeave expression that generates the output structure
Give some example mime type (formats) that the script will output
application/json, application/java, application/xml, text/plain, application/dw, application/csv, application/xlsx, …
What are the 2 types of DataWeave errors?
Scripting errors (syntax problems) and Formatting errors (a problem with how the transformation takes one format to another, there could be an issue if you are outputting an XML but the structure does no have a single root node))
If you get an error what can you do to check what type of error it is?
transform the input to application/dw, then if the transformation is successful it’s likely to be a formatting error
Dataweave syntax for a applcation/json output, fname: payload.firstname and {fname: payload.firstname} produce what outputs (if the firstname in the payload is “RayJones”?
{fname: “RayJones”} and {fname: “RayJones”}
same
What does an XML file need?
A root level (and only one).
Will this dwl code with an application/xml output write? — fname: payload.first, lname: payload.last
No, as it doesn’t have a one top-level value
How do you specify an attribute for an XML output? (you can have multiple attributes within the brackets).
@(attName: attValue)
Are attributes written to XML output as default?
No
XML input has an attribute ? Output application/json. What is the dataweave syntax to access the attribute?
payload.name.@initials
(which would give you
“ww”)
When using the map function what can the input array be?
JSON or Java
What does a map function do to an array?
IT takes each element in the array and applies the transformation function (or lambda function)
What does the map function return?
An array. (just think, if you are inputting an array and taking every value and transforming each value, it puts it back in the array).
Where is the transformation function used?
In the map function.
Within the transformation function what does the $ refer to?
value
Within the transformation function what does the $$ refer to?
Index