Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.92 KB

dataweave-cookbook-map-based-on-an-external-definition.adoc

File metadata and controls

55 lines (39 loc) · 1.92 KB

Dynamically Map Based on a Definition

You can create a transformation that can dynamically change what it does depending on a definition input. This DataWeave example receives both a payload input, and a variable named mapping that specifies how to rename each field and what default value to use in each. partial$dataweave1-links.adoc

The example uses the following:

  • A map function to go through all of the elements in the input array. Also a second map function to go through each field in each element.

  • A custom function that applies the changes specified in the mapping variable.

  • default to set a default value, that comes from the mapping variable.

DataWeave Script:
link:partial$cookbook-dw/map-based-on-an-external-definition/transform.dwl[role=include]
Input XML Payload:
link:partial$cookbook-dw/map-based-on-an-external-definition/inputs/payload.xml[role=include]
Input Mule Event Variable (JSON):
link:partial$cookbook-dw/map-based-on-an-external-definition/inputs/vars/mappings.json[role=include]
Output JSON:
link:partial$cookbook-dw/map-based-on-an-external-definition/out.json[role=include]